Javascript正则表达式允许使用逗号分隔的任何字符
在Javascript中,我需要正则表达式来允许文本框中任何逗号分隔的字符 示例:Javascript正则表达式允许使用逗号分隔的任何字符,javascript,regex,Javascript,Regex,在Javascript中,我需要正则表达式来允许文本框中任何逗号分隔的字符 示例: 有效字符串为: ie, ch, mz en, fa, ta /path/xyz , /test/apps/ msg_abc_chec.ts, ss_msg_abc_chec.ts com.app.fr, vi.dsx;gui 909.33.33.12312:343234, 33.23.33 800x480, 200x480, 1200x1060 ,
有效字符串为:
ie, ch, mz
en, fa, ta
/path/xyz , /test/apps/
msg_abc_chec.ts, ss_msg_abc_chec.ts
com.app.fr, vi.dsx;gui
909.33.33.12312:343234, 33.23.33
800x480, 200x480, 1200x1060 , 400x160
Main app, sub app
SomeAudOut#1 , SomeVidIn#3
ie,, ch, mz - 2 commas without string
en, fa, ta, - comma at the end
SomeAudOut#2 - no comma separated value
无效字符串包括:
ie, ch, mz
en, fa, ta
/path/xyz , /test/apps/
msg_abc_chec.ts, ss_msg_abc_chec.ts
com.app.fr, vi.dsx;gui
909.33.33.12312:343234, 33.23.33
800x480, 200x480, 1200x1060 , 400x160
Main app, sub app
SomeAudOut#1 , SomeVidIn#3
ie,, ch, mz - 2 commas without string
en, fa, ta, - comma at the end
SomeAudOut#2 - no comma separated value
它应该与此相匹配:
((.*)+,)*
你可以用
/^(?:[^,\n]+,)+[^,\n]+$/gm
看
-行首^
-1个或多个(?:[^,\n]+,)+
-1个或多个字符,而不是[^,\n]+,
(和换行符,但仅适用于多行模式)和,
,
-1个或多个字符,而不是[^,\n]+
或、
(同样,在多行模式下测试时需要\n
)\n
-行末$
即,ch,,mz
等行:
这里,
(?!*、\s*,)
阻止使用空格分隔的两个连续逗号的匹配行。检查此输入是否通过:/test/apps/,/test/apps/