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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.