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

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -