0

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 ?

0

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Why do you need the lookbehind? And you should add a \s* after look:.
@Tim: Hm. The look-behind is not necessary, you are right. I'll remove it. The \s* may or may not be correct.
Ah, I had only looked at the verbose regex (where at least some form of whitespace would have been necessary in this position), not at the concise form which always did contain the space.
when i tested this regex in my code it didnt catch and linkify, but when i test in regex tester it is returning true , also more info string can be like this (look: string1 string2 string3) meaning more than one string can follow look: so i have to linkify all in one link.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.