I'm not that savvy in regex, so I'm not sure how to achieve the following thing:
I'd like to capture any arbitary string from an input that may or may not be surrounded by the '$' character. If a '$' character is present at the beginning of the string, the '$' character at the end must be present.
Currently I have
^\w+([_.-]\w+)*$
which roughly translates to:
So valid matches would be:
test
test-5
test.1.3
test-alpha.2
Now I'd like to make this possible
$test$
But not...
$test (or test$)
^(?:(?:\w+(?:[_.-]\w+)*)|\$test\$)$
Its better to add that with |
instead off modifying the original one.See demo.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments