Hamza Talaghzi Hamza Talaghzi - 1 year ago 127
Javascript Question

Test a sentence statement with javascript and regex

Hi everybody!
I want to test a sentence like: "int a,b,c" for example is true or false
so I used the following code :

text="int a1,a2,a3"
if(/int ((([a-z_A-Z]+[0-9]*),)+)$/g.test(text)/g){

but the function test always return false

I don't know what the best expression I must test

Answer Source

You will need to add ? after the comma , to match between zero and one because the last number does not have afterward.

int ((([a-z_A-Z]+[0-9]*),?)+)$
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download