2011-06-15 23 views
2
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="); 

此代碼完美工作,但我無法得到它如何模式的工作原理和轉換隻Linkfy和Android作爲一個鏈接?使用模式Linkify

+0

當我把。 insted的&它沒有工作 – Parth 2011-06-15 10:57:48

回答

1

這是一個正則表達式。

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

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

它的說法得到 '快報其次&(符號)符號' 如果你把它改成一個。 (fullstop)。字符在正則表達式中有特殊的含義,所以你不能在這種情況下使用它。

你可以將其更改爲: [A-ZA-Z] + L

那麼類似的東西:

press LinkifyL or on AndroidL to search it on google 

將變爲一個鏈接,怎麼做呢?

+0

偉大的學習正則表達式的鏈接...謝謝 – kape123 2011-07-13 17:55:57

+0

另一個好工具 - > http://regexpal.com/ – kape123 2011-07-13 19:26:54

+0

如果你想使用&符號,你也可以只是逃避它所以它被識別爲字符而不是正則表達式關鍵字... – Makibo 2013-07-02 08:03:22