[GREP] Help find punctuations between brackets

Explorer ,
Jan 27, 2022 Jan 27, 2022

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.

TOPICS
Scripting

Views

194

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jan 27, 2022 Jan 27, 2022
Oh I see,  you have more than one group of parantheses... In this case use this: (\(.+?\K|(?R))*?,(?=[^()]+\))

Likes

Translate

Translate
Adobe Community Professional ,
Jan 27, 2022 Jan 27, 2022

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?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

try this

(?<=\\().*?(?=\\))

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2022 Jan 27, 2022

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))*[,.;:](?=.+\))

 

  

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2022 Jan 27, 2022

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

I tried with Find/change. 

weird…

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

here's a video that shows it 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2022 Jan 27, 2022

Copy link to clipboard

Copied

Oh I see,  you have more than one group of parantheses... In this case use this:

(\(.+?\K|(?R))*?,(?=[^()]+\))

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

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 ^^

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 27, 2022 Jan 27, 2022

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 !

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 27, 2022 Jan 27, 2022

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

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 08, 2022 Feb 08, 2022

Copy link to clipboard

Copied

LATEST

Terrific website. Didn't know it at all. Thanks for the tip 😉

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines