So I have these 2 expressions:
data-attribute@!#!19 => data-attribute19
data-attribute17 => data-attribute17
attribute19 => attribute
attribute1@!#!@#183 => attribute
You can do something a bit like this:
Which will match what you want, and then return the results inside either one or two capture groups (depending on which option it matches).
Breaking it Down
Going from left to right:
^ character means "beginning of line" - in this case, the beginning of a single string.
() indicate a capture group - some substring that you want to capture and output separately from your main match string.
data- indicates the literal string "data-", with the hyphen at the end.
[a-zA-Z0-9]+ is a character class, repeated one or more times.
.+? is one or more of any characters, matched lazily - meaning it will "give up" some of its match to enable the next token to match as much as possible.
\d* means zero or more digits (equivalent to
$ character means "match the end of the line" (again, in this case, the end of your string).
| character means "alternate" - basically, it will match either the pattern on the left or the pattern on the right, enabling this single regex to match either of your two strings.