I'm having a hard time with vscode's oniguruma regex parsing for TextMate. Apparently you can't use a newline inside a lookahead, even though oniguruma actually supports it, it's probably not enabled in vscode's version of oniguruma.
I need to match the beginning of a string if, and only if, after element
there is desiredAttr1="desiredValue1"
or desiredAttr2="desiredValue2"
:
<element attribute="value" desiredAttr1="desiredValue1" desiredAttr2="desiredValue2">
So far so good, but the thing is, these attributes can be in any order, and there can be a newline in between them. Eg.:
<!-- Should match -->
<element
attribute="value"
desiredAttr1="desiredValue1"
desiredAttr2="desiredValue2"
>
<!-- Should match -->
<element
attribute="value"
desiredAttr2="desiredValue2"
>
<!-- Should match -->
<element attribute="value" desiredAttr1="desiredValue1">
<!-- Should match -->
<element desiredAttr2="desiredValue2" attribute="value">
<!-- Should NOT match -->
<element
attribute="value"
notDesiredAttr1="desiredValue1"
notDesiredAttr2="desiredValue2"
>
This is what I got so far (and it works on rubular):
/(^[\t]+)?(?=<(?i:element)\b(?!-)[\s\w\W]*(?:((desiredAttr1="desiredValue1")|(desiredAttr2="desiredAttr2"))))/
Note: I tried also replacing \s
with [:space:]
and [^/]
This is what I need to match:
<span style="background: red;"> </span><code><element<br/>
attribute="value"<br/>
desiredAttr1="desiredValue1"<br/>
desiredAttr2="desiredValue2"<br/>
></code>
Is there any other alternative I could use? Thanks in advance.