Need Grep Pattern

48 views
Skip to first unread message

Kim Mosley

unread,
Apr 5, 2025, 8:22:05 PM4/5/25
to BBEdit Talk
To convert:

John Allen Doe    Justine Zen Center 

to 

John Allen Doe / Justine Zen Center / /john-allen-doe / 

Thank you!!!

GP

unread,
Apr 5, 2025, 9:09:12 PM4/5/25
to BBEdit Talk
BBEdit's Pattern Playground is a big help in constructing grep find and replace patterns. If you could use some help with regular expression grammar to use, there's a grep cheat sheet (the circled ? drop down menu) on the "Search patten:" line and Chapter 8, "Searching with Grep" in the BBEdit User Manual has additional information on grep patterns and syntax.

That said, assuming the name format in your example, a "Find:" (or "Search pattern:" for the Pattern Playground) grep pattern of:

(\w+) (\w+) (\w+)\s+(\w+ \w+ \w+)

 and a "Replace:" (or "Replace pattern:" for the Pattern Playground) grep pattern of:

\1 \2 \3 / \4 / \L/\1-\2-\3 /

will result in replacement text of:

John Allen Doe / Justine Zen Center / /john-allen-doe /

You may need to tweak the find grep pattern if there's some variation in spacing between the first, middle, and last name components. The above grep pattern assumes one and only one space between name components and one or more white space characters between the two names.

For an explanation of the \L in the replace grep, see the grep cheat sheet drop down next to the  Pattern Playground "Replace pattern:".
Reply all
Reply to author
Forward
0 new messages