文本从超链接问题Links Using Linkify

// 没有任何连接

textView.setAutoLinkMask(0);

 

 

// 电话数字  网页
Linkify.addLinks(text, Linkify.PHONE_NUMBERS | Linkify.WEB_URLS);

//正则表达式

Pattern pattern = Pattern.compile("\\d{5}([\\-]\\d{4})?");
String scheme = "http://zipinfo.com/cgi-local/zipsrch.exe?zip=";
Linkify.addLinks(text, pattern, scheme);

正则表达式 基本上很有用了,但是有时候需要更灵活写 比如我只要奇数,为了公司需要 还是英文解释吧 大家看得懂吧

// only accepts odd numbers.
MatchFilter oddFilter = new MatchFilter() {
   
public final boolean acceptMatch(CharSequence s, int start, int end) {
       
int n = Character.digit(s.charAt(end-1), 10);
       
return (n & 1) == 1;
   
}
};

// Match all digits in the pattern but restrict links to only odd numbers using the filter.
Pattern pattern = Pattern.compile("[0-9]+");
Linkify.addLinks(text, pattern, "http://...", oddFilter, null);

import java.util.regex.Pattern;
import android.text.util.Linkify;
import android.text.util.Linkify.TransformFilter;

// A transform filter that simply returns just the text captured by the
// first regular expression group.
TransformFilter mentionFilter = new TransformFilter() {
   
public final String transformUrl(final Matcher match, String url) {
       
return match.group(1);
   
}
};

// Match @mentions and capture just the username portion of the text.
Pattern pattern = Pattern.compile("@([A-Za-z0-9_-]+)");
String scheme = "http://twitter.com/";
Linkify.addLinks(text, pattern, scheme, null, mentionFilter);

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/text/util/Linkify.java

http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=core/java/android/text/util/Regex.java

 

 

你可能感兴趣的:(java,android,正则表达式,Scheme,git)