Regular match against opening parentheses not preceded by "]"
I have snippets of text where a regular markdown and a custom markup extension are mixed together. This works well enough.
[My Link Title]( ) (extension: value attribute: value)
However, I have one problem, apply some styles when editing text, I need a way to match the open parenthesis of the extension chunk without matching the open parenthesis of the markdown link.
- is not preceded by a character
My current regular expression for this (which works well to compare the parentheses extensions, but, unfortunately, includes brackets opening links by default) as follows:
I've seen people use regex negative negative imagery, sort of
Thanks for your advice!
The problem I am facing is that I am creating a "Simple Mode" syntax for CodeMirror in order to apply highlighting. This allows you to specify a regular expression and token to be applied to the matched characters, but does not allow further match operations. However, you could write a full syntax mode where you can do operations like this, but I am not capable of that: -s
In the end, I went with a different solution. I just created two regular expressions:
- Match all the opening parentheses of the extension to the previous character followed by "]":
- Matches all opening parentheses of an extension without a leading character:
Even though this is not the cleanest way, it seems to work very well now.
source to share
Using the skip trick :
links (you can also write
if it's too confusing), OR -
- match and freeze open parentheses that appear immediately before an alphanumeric character.
Working example: https://regex101.com/r/tY9sS4/1
You will need to see the result and only handle the matches where the group is
grouped and ignore the rest of the matches.
source to share