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

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -