javascript - Trying to get a regex to recognize and extract words from both camelCase and CamelCase -
i've got halfway working. works great:
'myownvar'.match(/([a-z]*)([a-z][a-z]+)/g)
result:
["my", "own", "var"]
the goal pull out individual words. if pass camelcase name it:
'myownvar'.match(/([a-z]*)([a-z][a-z]+)/g)
i get:
["myown", "var"]
i can't figure out i'm doing wrong. far can tell, 2 sets of ()
should store matching results in 2 separate array elements. it's lumping them in reason.
if have understood question following regex should trick:
/([a-za-z][a-z]+)/g
in case single character (as "m" in "mownvariable") should considered word:
/([a-za-z][a-z]*)/g
Comments
Post a Comment