I’m trying to isolate array name and array size from code. This example of expected input:
blah_blah[blahvar]
blah_ha[2]
blah_[]
I need to match names (blah_blah, blah_ha, blah_) and text inside brackets (blahvar, 2, ”).
I have this regex:
([a-zA-z_]+)(\[[a-zA-Z_]*\])
But it’s not working. Please help.
You need to include numbers:
([a-zA-z_0-9]+)(\[[a-zA-Z_0-9]*\])Without that, your second example
blah_ha[2]won’t catch (the others do).A shorter version (that captures every word character (letters, digits, etc.):
(\w+)(\[\w*\])