view raw
Hamza Talaghzi Hamza Talaghzi - 6 months ago 37
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


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]*),?)+)$