[英]Javascript regular expression for complex string
I want to create a regex which will match string like "123;qwe;12324", this regex is working fine: 我想创建一个正则表达式,它将匹配“ 123; qwe; 12324”之类的字符串,该正则表达式可以正常工作:
[a-zA-Z0-9;]
But I want to allow blank spaces also if preceded or followed by ; 但是,如果要在前面或后面加上空格,我想也要留空; but this is not working:
但这不起作用:
[a-zA-Z0-9;\s(?=;)]
Can someone please help. 有人可以帮忙吗?
I guess 我猜
/^([a-zA-Z0-9]+\s*;\s*)*[a-zA-Z0-9]+$/
Test 测试
> re.test('abc')
true
> re.test('abc;def')
true
> re.test('abc; def')
true
> re.test('abc; def;')
false
> re.test('abc^^^; def;')
false
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.