I have two types of patterns, as below:
- Type I:
${<varName>}
- Type II:
$${<varName>}
The patterns can be found standing alone, or contained multiple matches in a string. I need to find the occurrences of these patterns, so I wrote a query to search by matching regex. However, the problem is that for any Type II pattern, they themselves contain a match for Type I pattern. For example, $${newVar}
will be detected twice as $${newVar}
and ${newVar}
. I only want the former to be returned. The regular expressions I used are:
- Type I:
\$\{[a-zA-Z0-9]+\}
- Type II:
\$\$\{[a-zA-Z0-9]+\}
You can see an example of the detected string here (below)
Note that the second detection is correct, whereas the first detection is unwanted.
Is there anyway too modify these regular expressions to meet my need? Or is there any alternatives? Please feel free to suggest. All answers are welcome!! Thank you all.