extract the first word from a string - regex -
i have following string:
str1 = "cat-one,cat2,cat-3"; or str1 = "catone,cat-2,cat3"; or str1 = "catone"; or str1 = "cat-one";
the point here words may/may not have "-"s in it
using regex: how extract 1st word?
appreciate on this.
thanks, l
it's pretty easy, include allowed characters in brackets:
^([\w\-]+)
Comments
Post a Comment