Skip to main content
Known Participant
July 29, 2022
Answered

Making groups in GREP

  • July 29, 2022
  • 1 reply
  • 211 views

I want to write a GREP code to do this:
Between the words X and Y, find one thinspace or more OR find two spaces or more. 
I've written this command:

(\bX\b)[~<]{1,}]|[  ]{2,}(\bY\b)

although it logically is what I want, however it does not work. It seems the | can't tell the correct part of commands it must apply to. I personally think there should be something like parathesis to group my Grep code.

This topic has been closed for replies.
Correct answer jctremblay

You need to wrap the OR inside a ( ) like so:

 

(\bX\b)([~<]{1,}]|[ ]{2,})(\bY\b)

 

But it could be reduced to just this (two regulars spaces before the +):

 

\bX(~<+|  +)Y\b

 

 

1 reply

jctremblay
Community Expert
jctremblayCommunity ExpertCorrect answer
Community Expert
July 29, 2022

You need to wrap the OR inside a ( ) like so:

 

(\bX\b)([~<]{1,}]|[ ]{2,})(\bY\b)

 

But it could be reduced to just this (two regulars spaces before the +):

 

\bX(~<+|  +)Y\b