开发者

Linkify using pattern

Pattern pattern = Pattern.compile("[a-zA-Z]+&");
    myCustomLink.setText("press Linkify& or on Android& to search it on google");
    Linkify.addLinks(myCustomLink,pattern, "http://www.google.ie/search?q=");

This code works perfectly but I c开发者_StackOverflowannot get it how patterns works and convert only Linkfy and Android as a link ???


It's a regular expression.

http://www.marksanborn.net/howto/learning-regular-expressions-for-beginners-the-basics/

http://www.regular-expressions.info/reference.html

it's saying get ' Letters followed by the &(ampersand) sign ' if you changed it to a . (fullstop) the . character has a special meaning in regex so you can't use it in this situation.

You could change it to: [a-zA-Z]+L

then anything like:

 press LinkifyL or on AndroidL to search it on google

will change to a link, get it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜