It can be adapted for 2-10 words; it's just along expression.
As you can see, what I provided…
===
FIND:
(?:^2 PLAC(?: \d+) \K(\w+)(\h\w+)(\h\w+)(?=\h\w+$))|(?:^2 PLAC(?: \d+)
\K(\w+)(\h\w+)(\h\w+)(\h\w+)(?=\h\w+$))
CHANGE TO: \1,\2,\3,\4
===
…has one instance of *(\w+)* followed by 2 instances of *(\h\w+)*
followed by *(?=\h\w+$))* in the segment before the first vertical bar,
while the segment after the first vertical bar is the same, but contains
3 instances of *(\h\w+)*.
So what needs to be done is to add more segments, each separated by a
vertical bar except for the last one (since the vertical bar means "OR").
To clarify, the *(?:^2 PLAC(?: \d+) \K* processes and ignores the the
start of the line…
*2 PLAC*, followed by an optional set of digits preceded by a space,
followed by a space.
So it's just a question of stacking more instances, one with only one
*(\h\w+)*, for the shortest possibility, and the rest with yet an
additional instance of *(\h\w+)* , separating each with a vertical bar.
Rick Gordon
--------
On June 7, 2023 at 9:37:27 PM [-0700], Dave Simpson wrote in an email
entitled "Re: Replacing all spaces in a line, but not the first":
Hi Rick
Many thanks for that, it works a treat (within limits)!
When I say that, it works fine for lines where the address is 4
elements long.
e.g. /2 PLAC 49 Spinney Close Northfield Birmingham/
converts to /2 PLAC 49 Spinney, Close, Northfield, Birmingham/
/
/
However if there are fewer or more elements it ignores the line.
A PLAC entry can be in the range 1 to 10 elements
e.g. / 2 PLAC 46 Norton Crescent Alum Rock Birmingham /has 5 elements
and is ignored
as is /2 PLAC Kalamzoo Birmingham /which is 3 elements
/
/
I'm beginning to think that I'm asking too much, as a PLAC entry can
be in the range 1 to 10 elements
_Having just written that, a solution came to mind:_
If I change the Replace statement to/ \1,\2,\3,\4,\5,\6,\7,\8,\9,\10
/that will put superfluous commas in place
e.g. /2 PLAC 33 Barker, Street, Shrewsbury,,,,,,, Shropshire/
However, it is a simple matter to remove the extra commas.
I can fix the things like Street, Road etc afterwards, it was the
initial adding of the commas that was giving me a problem.
Very many thanks for your efforts
Dave
On Wednesday, June 7, 2023 at 9:24:02 PM UTC+1 Rick Gordon wrote:
Try this:
===
FIND:
(?:^2 PLAC(?: \d+) \K(\w+)(\h\w+)(\h\w+)(?=\h\w+$))|(?:^2 PLAC(?:
\d+)
\K(\w+)(\h\w+)(\h\w+)(\h\w+)(?=\h\w+$))
CHANGE TO: \1,\2,\3,\4
===
That should ignore the first number and handle groups of either 3
or 4
words afterwards. It could be further modified if longer groups are
possible.
It doesn't handle street names in the most intelligent way, as it
will
put a comma after the street name. And if any words had
punctuation in
them (like "St.", or a hyphen), that would require further
modification.
Rick Gordon
----------
On June 7, 2023 at 1:18:08 PM [-0700], Dave Simpson wrote in an email
entitled "Re: Replacing all spaces in a line, but not the first":
> Hi Kaveh
>
> I'm not sure that that would solve it.
>
> It first needs to find the lines beginning with "2 PLAC " and act
only
> on those lines.
> Replacing "2 PLAC " with something else would give the same
issue, it
> would have to find only those lines beginning with our substitute
label.
>
> Many thanks for your help.
> Think I'll put it on the back burner for now.
>
> Regards
> Dave
> On Wednesday, June 7, 2023 at 8:52:23 AM UTC+1 Kaveh Bazargan wrote:
>
> Ah, I thought all lines had that.
>
> Then you could replace "2 PLAC " (with space) with a unique
> string, e.g. ●, and at the end replace ● by "2 PLAC "
>
> Not sure that would solve it.
>
> On Tue, 6 Jun 2023 at 19:02, Dave Simpson <[email protected]> wrote:
>
> Hi Kaveh
> Sorry about the delay in replying, had to go out.
> I’m a bit confused as to how the 2 PLAC can be put back to
> correct line
>
> Not every line in the file begins with 2 PLAC
>
> Dave
>
> On Tuesday, June 6, 2023 at 4:29:21 PM UTC+1 Kaveh Bazargan wrote:
>
> BTW to replace
>
> 2 PLAC
>
> at start of lines when replacements have been done, replace:
>
> "^" -- start of line
> with
>
> "2 PLAC "
>
> On Tue, 6 Jun 2023 at 15:28, Kaveh Bazargan
> <[email protected]> wrote:
>
> Simplest might be first to remove all "2 PLAC "
>
> Then replace
> "(?<!(?:[0-9]))"
> with
> ", "
>
> So replace any space not preceded by a digit to a
> comma space.
>
> Would that work?
>
> On Tue, 6 Jun 2023 at 15:19, Dave Simpson
> <[email protected]> wrote:
>
> Hi Kaveh
>
> No problem, 3 examples of before and after
>
> 2 PLAC 129 Haymarket London England
> 2 PLAC 129 Haymarket, London, England /[Ideal
> answer because space between '129' and 'Haymarket'
> is skipped, but not essential]/
>
> 2 PLAC 24 Long Street Chester Cheshire
> 2 PLAC 24, Long, Street, Chester, Cheshire
>
> 2 PLAC Meadows, Lowestoft, England
> 2 PLAC Meadows Lowestoft England
>
> Thanks
> On Tuesday, June 6, 2023 at 2:48:07 PM UTC+1 Kaveh
> Bazargan wrote:
>
> Hi Dave
>
> Could you give several examples of before,
> then the same ones after?
>
> Regards
> Kaveh
>
> On Tue, 6 Jun 2023 at 14:45, Dave Simpson
> <[email protected]> wrote:
>
> Hi, I'm a novice at this sort of thing.
>
> I have a line of text:-
> /2 PLAC 11 Haymarket Willenhall Staffordshire/
>
> I want to replace the spaces with ,
> [comma space] after the first part of the
> line [2 PLAC ]
>
> ^(2 PLAC ) finds me the start
> Now I want to replace the spaces with
> comma space:-
>
> /2 PLAC 11, Haymarket, Willenhall,
> Staffordshire/
> [It would be brilliant if it were possible
> to skip the first space between 11 and
> Haymarket]
> /
> /
> Many thanks for your help
>
> --
> This is the BBEdit Talk public discussion
> group. If you have a feature request or
> need technical support, please email
> "[email protected]" rather than posting
> here. Follow @bbedit on Twitter:
> <https://twitter.com/bbedit>
> ---
> You received this message because you are
> subscribed to the Google Groups "BBEdit
> Talk" group.
> To unsubscribe from this group and stop
> receiving emails from it, send an email to
> [email protected].
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/bbedit/8ef6eae3-ca41-4f50-bf72-c4394a8fee8fn%40googlegroups.com
>
<https://groups.google.com/d/msgid/bbedit/8ef6eae3-ca41-4f50-bf72-c4394a8fee8fn%40googlegroups.com?utm_medium=email&utm_source=footer
<https://groups.google.com/d/msgid/bbedit/8ef6eae3-ca41-4f50-bf72-c4394a8fee8fn%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies
> <http://rivervalley.io> ● Twitter
> <https://twitter.com/rivervalley1000> ●
> LinkedIn
> <https://www.linkedin.com/in/bazargankaveh/>●
> ORCID <https://orcid.org/0000-0002-1414-9098>
> ● @[email protected]
> <https://mastodon.social/@kaveh1000>
> *Accelerating the Communication of Research*
>
*<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop
<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>>
>
https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/
>
<https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
> *
>
> --
> This is the BBEdit Talk public discussion group.
> If you have a feature request or need technical
> support, please email "[email protected]"
> rather than posting here. Follow @bbedit on
> Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are
> subscribed to the Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving
> emails from it, send an email to
> [email protected].
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/bbedit/34efcbe2-6182-4ce7-a737-900da7c534can%40googlegroups.com
>
<https://groups.google.com/d/msgid/bbedit/34efcbe2-6182-4ce7-a737-900da7c534can%40googlegroups.com?utm_medium=email&utm_source=footer
<https://groups.google.com/d/msgid/bbedit/34efcbe2-6182-4ce7-a737-900da7c534can%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies <http://rivervalley.io> ●
> Twitter <https://twitter.com/rivervalley1000> ●
> LinkedIn <https://www.linkedin.com/in/bazargankaveh/>●
> ORCID <https://orcid.org/0000-0002-1414-9098> ●
> @[email protected]
> <https://mastodon.social/@kaveh1000>
> *Accelerating the Communication of Research*
>
*<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop
<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>>
>
https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/
>
<https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
> *
>
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies <http://rivervalley.io> ●
> Twitter <https://twitter.com/rivervalley1000> ● LinkedIn
> <https://www.linkedin.com/in/bazargankaveh/>● ORCID
> <https://orcid.org/0000-0002-1414-9098> ●
> @[email protected] <https://mastodon.social/@kaveh1000>
> *Accelerating the Communication of Research*
>
*<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop
<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>>
>
https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/
>
<https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
> *
>
> --
> This is the BBEdit Talk public discussion group. If you have a
> feature request or need technical support, please email
> "[email protected]" rather than posting here. Follow
> @bbedit on Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the
> Google Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to [email protected].
>
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/bbedit/293f45d2-3ed3-44d0-891f-fc32d61df2f3n%40googlegroups.com
>
<https://groups.google.com/d/msgid/bbedit/293f45d2-3ed3-44d0-891f-fc32d61df2f3n%40googlegroups.com?utm_medium=email&utm_source=footer
<https://groups.google.com/d/msgid/bbedit/293f45d2-3ed3-44d0-891f-fc32d61df2f3n%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies <http://rivervalley.io> ● Twitter
> <https://twitter.com/rivervalley1000> ● LinkedIn
> <https://www.linkedin.com/in/bazargankaveh/>● ORCID
> <https://orcid.org/0000-0002-1414-9098> ● @[email protected]
> <https://mastodon.social/@kaveh1000>
> *Accelerating the Communication of Research*
>
*<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop
<https://www.linkedin.com/posts/bazargankaveh_ismte-innovation-award-recipient-kaveh-bazargan-activity-7039348552526921728-XAEB/?utm_source=share&utm_medium=member_desktop>>
>
https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/
>
<https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/>
> *
>
> --
> This is the BBEdit Talk public discussion group. If you have a
feature
> request or need technical support, please email
> "[email protected]" rather than posting here. Follow @bbedit on
> Twitter: <https://twitter.com/bbedit>
> ---
> You received this message because you are subscribed to the Google
> Groups "BBEdit Talk" group.
> To unsubscribe from this group and stop receiving emails from it,
send
> an email to [email protected]
> <mailto:[email protected]>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/bbedit/8df13542-9166-43a7-998e-8bdc7090cea1n%40googlegroups.com
>
<https://groups.google.com/d/msgid/bbedit/8df13542-9166-43a7-998e-8bdc7090cea1n%40googlegroups.com?utm_medium=email&utm_source=footer
<https://groups.google.com/d/msgid/bbedit/8df13542-9166-43a7-998e-8bdc7090cea1n%40googlegroups.com?utm_medium=email&utm_source=footer>>.
___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com
--
This is the BBEdit Talk public discussion group. If you have a feature
request or need technical support, please email
"[email protected]" rather than posting here. Follow @bbedit on
Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google
Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected]
<mailto:[email protected]>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/58bab2c5-8ca6-450c-9ed4-bba2df3af9f9n%40googlegroups.com
<https://groups.google.com/d/msgid/bbedit/58bab2c5-8ca6-450c-9ed4-bba2df3af9f9n%40googlegroups.com?utm_medium=email&utm_source=footer>.
___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com
--
This is the BBEdit Talk public discussion group. If you have a feature request or need
technical support, please email "[email protected]" rather than posting here.
Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/64815EA3.2080303%40rickgordon.com.