Copy link to clipboard
Copied
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.
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
Hi Mike,
Try the following and tell if it works or not, if it does i will explain what is happening
^\[[^[]*?\]
-Manan
Copy link to clipboard
Copied
Hi Mike,
Try the following and tell if it works or not, if it does i will explain what is happening
^\[[^[]*?\]
-Manan
Copy link to clipboard
Copied
I guess you have known the answer already 🙂
Curious to see how does it work ?
thanks
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.