satvrn
satvrn5mo ago

✅ – satvvrn – 15-47 Jun 12

I need a little Regex help. Consider the following string: x..y..x..z. I want to match x..y and x..z separately. x(.+?)z matches x..y..x..z which is Not what I want. What Regex pattern would match only x..z?
Solution:
Message Not Public
Sign In & Join Server To View
Jump to solution
13 Replies
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
satvrn
satvrn5mo ago
But that would match both x..y and x..z. I want a Regex that discards/does not match x..y nor x..y..x..z, only x..z
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
satvrn
satvrn5mo ago
That would work for this case, but I see I might've made the example too abstract. In my specific case I have the following string:
Address: 123 Test St (Home)
Address: 456 Test Ave (Work)
Address: 123 Test St (Home)
Address: 456 Test Ave (Work)
I effectively want to match Address: 456 Test Ave (Work). "x" is "Address:", "y" is "(Home)" and "z" is "(Work)" [^x] wouldn't work in my case.
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
satvrn
satvrn5mo ago
The negative lookahead worked, thanks!
No description
reactibot
reactibot5mo ago
This question has an answer! Thank you for helping 😄 If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1250476632045785203
satvrn
satvrn5mo ago
Followup question: Apparently, the example above only works if there's a newline in the middle. When removing the newline, it starts not working again: How would I fix?
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
satvrn
satvrn5mo ago
It doesn't change anything, though
No description
Unknown User
Unknown User5mo ago
Message Not Public
Sign In & Join Server To View
satvrn
satvrn5mo ago
That seems to make it work. I ended up using Address: ((?:(?!Address:).)*) \(Work\) to have $1 be just the full address. Thanks again!
reactibot
reactibot5mo ago
This thread hasn’t had any activity in 36 hours, so it’s now locked. Threads are closed automatically after 36 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1250476632045785203