jquery - Regex pattern in Javascript -
i want match string pattern has first 4 characters, "|" symbol, 4 characters, "|" symbol again , minimum of 7 characters.
for example, "test|test|test123"
should matched.
i tried regexp("^([a-za-z0-9-|](4)[a-za-z0-9-|](5)[a-za-z0-9-|](3)+)$")
this, didn't match test case.
test|test|test1234
ramesh, want?
^[a-za-z0-9-]{4}\|[a-za-z0-9-]{4}\|[a-za-z0-9-]{7,}$
you can try @ https://regex101.com/r/jilo6o/1
for example, following matched:
- test|test|test123
- a1-0|b100|c10-200
- a100|b100|c100200
but following not:
- a10|b100|c100200
- a100|b1002|c100200
- a100|b100|c10020
tips on modifying original code.
you have "a-za-z" intended "a-za-z", allow either upper or lower case.
to specify number of characters 4, use "{4}". there round brackets, need curly, specify count.
to specify range of number of characters, use "{lowerlimit,upperlimit}". leaving upper limit blank allows unlimited repeats.
we need escape "|" character because has special meaning of "alternate", in regular expressions, i.e. "a|b" matches either "a" or "b". writing "\|" regex interpreter knows want match "|" character itself.
Comments
Post a Comment