Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP syntax explanation request

Participant ,
May 14, 2020 May 14, 2020

There is a paragraph as in the frame 1#.  My intention is to define text style, that makes bold ANY text in square brackets at the beginning of the paragraph. So it will look as in the frame 2#

The GREP syntax is shown below.

p1.jpg

 

This acts however in such a way, that if there is other text in sq brackets somwhere in the paragraph, and I type manually opening square bracket at the begining of paragraph, the whole text becomes overset.

1/ can sb explain why it is so?

2/ what is the correct GREp syntax to avoid this ?

 

TIA

TOPICS
How to , Type
825
Translate
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

Community Expert , May 14, 2020 May 14, 2020

Hi Mike,

Try the following and tell if it works or not, if it does i will explain what is happening

^\[[^[]*?\]

 

-Manan

Translate
Community Expert ,
May 14, 2020 May 14, 2020

Hi Mike,

Try the following and tell if it works or not, if it does i will explain what is happening

^\[[^[]*?\]

 

-Manan

Translate
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
Participant ,
May 14, 2020 May 14, 2020

I guess you have known the answer already 🙂

Curious to see how does it work ?

 

thanks

Translate
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 Expert ,
May 14, 2020 May 14, 2020

Ok so lets dissect this

Your regex was ^\[.+?\]

Here ^ means start the match from the start position

\[ matches the character [ literally, since [ has a special meaning in regex so it is escaped by precedding it with a \

. matches any character, + means one or more occurence of the preceding character. So .+ means any character matches any number of times

? means match as little as needed to complete the whole match

and lastly \] matches the ] character

So in totality this means match a string where the first character is [ followed by any no. of characters unless we hit a ]. Now the issue with this is that the any character can also include a [ character and hence it we have [xxx] in the path the [ will neglected and the match include string untill the last ]

 

So what i did was tell that after the first [ we can have any no of characters which can be anything execpt a [ character. This is done by using character classes so instead of your .+ i used [^[]. Here text enclosed inside [] dentoes the character class, and inside it we can give a set of allowed characters, if you want to negate the set then you preceed it with a ^ so [^[] means any character except [ character.

 

Hope this did not get too confusing. Also look at the following link to read the description of grep in a more viscual way, look at the right hand pane for explanation of the expression

https://regex101.com/r/0dIi5Z/2

 

-Manan

Translate
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
Participant ,
May 14, 2020 May 14, 2020
LATEST

Manan,

 

thanks a lot. Since I realised the problem was forgetting that any char can also be [  🙂 , your syntax is obvious.

appreciate your effort to help & clarify.

Translate
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