Wednesday, 2 October 2013

Complex Regex composition - Regex that match "if"

Complex Regex composition - Regex that match "if"

I'm making a Regex to match hashtags to my project. I want that regex
match hashtags that are separeted by one single space, don't have another
hashtag inside this content and just match a space in the string if this
is followed by any word (except other blank space or #).
I'm really curious to know if I can do something like "if" in regular
expressions and I hope you can help me with this.
So, in:
"#hashtag?!-=_" "#hashhash#" "#hash tag" "#hash tag" "#hash
#ahuhuhhuasd" "#hash "
The regex must match the following sentences:
"#hashtag?!-=_" "#hashhash" "#hash tag" "#hash" "#hash #ahuhuhhuasd" "#hash"
(all hashtag) (one) (another h.)
Actually, this is my code:
#{1,1}\S+\s{0,1}
You can test here this code, but it matches things that isn't desired:
"#ahusdhuas?!__??###hud #ahusdhuads "
The blank space in the end of the string, the 3 '#' inside the string.
none of the following content is desired in this string, just
"#ahusdhuas?!__??"
Glad if you can help me!

No comments:

Post a Comment