Hi all, I would need help writing a Grep syntax to change a string of text like this:
House, Big Apple, Today, Movie
into this:
[[House]] | [[Big Apple]] | [[Today]] | [[Movie]]
Almost exactly, because it will give you
[[House]]|[[Big Apple]]|[[Today]]|[[Movie]]|
Note the extra vertical bar at the end of the line. The simplest thing is to follow up this up by removing the trailing vertical bars withFind:|$A BBEdit text factory makes it simple to automate doing two or more find-and-replaces .Replace: (nothing)The problem is that you want to change every “fragment” in a line to “[[fragment]]|” except for the last fragment, which you want to change to “[[fragment]]”, and there is no way to write a single regular expression find-and-replace that has chooses among different replacement patterns based on the content or context of the matched pattern.
Find: (?x) (?# 1: Leading space) [ ]* (?# 2: Fragment) ([^\n,]*?) (?# 3: trailing space) [ ]* (?# 4: separator) (?:,|(\n))
Replace: [[\1]]|\2
On Oct 18, 2024, at 3:56 PM, Rob Russell <sum...@gmail.com> wrote:that's a really good explanation.What is the first (?x) for in your find string? I read that as searching for an x. My limited knowledge of Grep expects (?\x )
(?x) (?# 1: Leading space) [ ]* (?# 2: Fragment) …
--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@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 bbedit+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/C97A5C90-3123-4942-9016-A034181FC7B9%40faiman.org.