开发者

Linkify using pattern

开发者 https://www.devze.com 2023-03-12 22:46 出处:网络
Pattern pattern = Pattern.compile(\"[a-zA-Z]+&\"); myCustomLink.setText(\"press Linkify& or on Android& to search it on google\");
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

精彩评论

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