Home > Enterprise >  How to rematch the first word or '(' the first word at the beginning
How to rematch the first word or '(' the first word at the beginning

Time:07-15

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 /)));

  • Related