I have string that include (look: string) (in this format) within the text that displayed in my "textview" i wanna linkify the "string" part and than delegate to another activity , how can i achieve this, my knowladge about regular expression is not so good ?
2 Answers
The regex to identify a "(look: string)" substring would be along the lines of
\(look: (\S+)\)
explanation
\( # opening parenthesis
look: # the string "look: "
( # begin match group 1
\S+ # anything but a space (insert bells-n-whistles URL regex here)
) # end match group 1
\) # a closing parenthesis
The \S+ is close enough to handling a URL (as they cannot contains spaces) if you generally expect URLs at this position. If other things might appear there as well, you could insert a more advanced check here. URL matching regexes are plenty, if you search for them.
For all matches, you are interested in the contents of group 1, which you can use to create links.
4 Comments
\s* after look:.\s* may or may not be correct.Here is a last version i am using , this time doesnt need to be match the string after look just matching all of them including look , but look may followed by one or more string ended with bracket.
\(look: .+ \)
This will catch (look: string ) , (look: string string ) and any more string followed