javascript - Need a specific regular expression -
i create following regex:
* [ * , * ] * where * can text of size have tried following:
/[*.,.*]/ but not (if matters need javascript)
examples correct text:
- test[1,2]
- test[3,test2]
can help?
try this:
[^\[]*\[[^\]]*\] ^----^ [ ^^ - [ ^----^ - ] ^^ - ] optionally can wrap whole regex in ^ , $ match whole string only.
example:
> /^[^\[]*\[[^\]]*\]$/.test("test[1,2]") true > /^[^\[]*\[[^\]]*\]$/.test("test[1,test2]") true > /^[^\[]*\[[^\]]*\]$/.test("test_wrong") false > /^[^\[]*\[[^\]]*\]$/.test("test[wrong") false
Comments
Post a Comment