regex - Regular Expression to match C data type -


i have strings

int int[] char[] int[][] char** int* etc 

i want regular expression match this. best have been able come

[a-za-z]+(\[\])?(\*)? 

this works for

int int[] char[] int[] int* char* 

but validates int[]* , not validate int[][].

int, char, etc. not important , examples.

try:

[a-za-z]+((\[\])+|(\*)+)? 

the | operator means "or." + operator means "one or more of previous." therefore, regex means "some letters, optionally (one or more []s) or (one or more *s)."

here jsfiddle.


Comments