Copy link to clipboard
Copied
Hi guys,
I'm having difficulties understanding my problem here. If anyone can help, I'll be very thankfull š
I would like to find any punctuation between brackets in order to apply a condition on them (via a script). But my grep doesn't work š
I thought I could modify another grep expression, the following one, that is looking for everything between brackets. This one works fine and I'm using it a lot.
(?<=\().*?(?=\))
If I consider using the posix [[:punct:]], why the following expression doesn't work, what should be done in order to fix it ?
(?<=\()[[:punct:]]*?(?=\))
Thanks for your insight
Example: (need to get the 2 commas between the brackets, but not the one outside)
Hello Indesign folks (men, women, possibly lost aliens), I need your help.
Copy link to clipboard
Copied
That is only going to work if there is nothing but punctuation between the parentheses. Can you show us some examples of the actual text you will be searching?
Copy link to clipboard
Copied
Thanks for you reply.
The overall goal is to use a script that sorts alpha words separated with commas. The script makes it done as long as there aren't any unwilling commas in the sentence, like the one that appear between parentheses.
I'd like write a script that can "neutralise" every commas thar are between the parentheses. The main frame of the script is done, except the Grep expression for finding the commas.
Ex 1: I'd like to be able to
I can easily sort the words :
- Punching, Licking, Throwing
because they are "simply" separated by commas.
Ex2: I cannot use my script yet with the folowwing sentence
- Punching (Boxing, Wing Chun, Karate), Kicking (Kickboxing, Taekwondo, Capoeira, Savate), Throwing (Hapkido, Judo, Sumo, Wrestling, Aikido)
because of the commas appearing between the parentheses.
I'd like to write a grep expression that allows me to select the commas between:
Boxing, Wing / Chun, Karate / Kickboxing, Taekwondo / Taekwondo, Capoeira / Capoeira, Savate / Hapkido, Judo / Judo, Sumo etc.
This way, I could apply a conditional text that will "hide" the commas. I'll then apply my sort script and delete the contion for the whole text to reappear.
Copy link to clipboard
Copied
try this
(?<=\\().*?(?=\\))
Copy link to clipboard
Copied
That's the one I'm using (see my first post) but selects the whole text between parentheses.
For some reasons (linked to the behavior of the sort script) I need to focus on only looking for the commas.
Copy link to clipboard
Copied
Try this one...
(\(.+?\K|(?R))*,(?=.+\))
If you need to select more than just the , use this one and add your punctuations inside the [ ] like so.
(\(.+?\K|(?R))*[,.;:](?=.+\))
Copy link to clipboard
Copied
Merci Jean-Claude pour ta rƩponse,
A hell of an grep !
Very close to what I'd like to achieve, butā¦
The expression reaches every single punctuation (which is already good, something I didn't succeed to) but the thing is, I'd like to reach only the ones between parentheses.
I'm still not much familiar with the \K and \R and wonder what to modifiy to narrow the search between the parentheses
Copy link to clipboard
Copied
This GREP only select the , when between parentheses.
Have you try it in Find/Change or GREP Style?
\K or (?R) might not be supported in javascript
Copy link to clipboard
Copied
I tried with Find/change.
weirdā¦
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Oh I see, you have more than one group of parantheses... In this case use this:
(\(.+?\K|(?R))*?,(?=[^()]+\))
Copy link to clipboard
Copied
I knew you were a genius, now, I experience it ^^
Works as a charm. Thank you very much !
Will see soon enough if this still works with javascript ^^
Copy link to clipboard
Copied
⦠and I have to do my homework in order to understand this quite complex grep expression. There is no way I could have found it by myself.
Thanks again !
Copy link to clipboard
Copied
This one is working also... and should probably be the one to use.
\(.+|\G.+?\K,(?=[^()]*\))
Get an explanation of the code at Regex101:
https://regex101.com/r/KbUaM3/1
Copy link to clipboard
Copied
Terrific website. Didn't know it at all. Thanks for the tip š