Supposing I have the following text:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod ,,,,,,tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ,,,,,nostrud exercitation ullamco [,] laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu [,,,,,] fugiat nulla pariatur. Excepteur sint {,,}occaecat cupidatat non proident, sunt {,,,,,} in culpa qui officia deserunt mollit anim id ,,,,,est laborum.
I would like to select all commas in the text with the following pattern
(\,{2,99})
but then I also would like to specify the same filter to be applied only between specific characters like selecting only the commas between [] or {} but not [} for example.
where this would fail:
(\[|\{) (\,{2,99}) (\]|\})
and the following would work as expected
(\{) (\,{2,99}) (\}) | (\[) (\,{2,99}) (\])
so the thing is that I am having to re-type (\,{2,99}) every time I want to surround this match with another selection.
Is there any way to declare inside the same command a variable that could be applied later on? like:
$1=(\,{2,99}) | (\{$1\}) | (\[$1\])
I hope this is easy to understand, please bear with me since regular expersions are really a new thing in my case, so all these declarations might look terrible for you 🙂
I would appreciate if you could notice something badly written here and recommend a better way to it.
Please also mind that this example for catching all the commas was for demonstrative purposes on how I would like to re-use a bit of code more times inside the same command…you could replace that simple selector with something huge that you wouldn’t like to re-type every time?
Thanks in advance
You can use a variable and concatenate it several times with your regex.