Reputation: 107
Consider 2 of the following:
My regex: trans\(([\'"])(((?!\1).)*)\1\)
The above works well with the 2. case but does not work with case 1. I tried adding another capturing group (/s) but then 2. does not work while 1. does. Is there a way to have both detected?
Upvotes: 0
Views: 1117
Reputation: 1
It looks like you want symmetrical quotes and whitespace, and to capture the string in between.
trans\((\s*)(['"])(((?!\2).)*)\2\1\)
The string is in $3.
Upvotes: 0
Reputation: 188
The following should work as it's simply modifying your expression to support any number of whitespaces on either side of the quotes:
trans\(\s*([\'"])(((?!\1).)*)\1\s*\)
Upvotes: 2
Reputation: 522817
The following pattern seems to work here:
trans\((\s*)(['"])(.*?)\2\1\)
Here we capture optional whitespace before the singly quoted term, and then ensure that we also match the same as \1
after that term. For those inputs having whitespace, we assert that we see the same whitespace afterwards. For inputs not having whitespace, then \1
should be empty.
Upvotes: 1