str = "find().nodes() as n3" ==> find
str = "with n1,n2,n3" ===> with
CodePudding user response:
Use string match
with the regex pattern ^\w
:
var inputs = ["find().nodes() as n3", "with n1,n2,n3"];
inputs.forEach(x => console.log(x " => " x.match(/^\w /)));