Android的与正则表达式替换 [英] Android replace with regex
本文介绍了Android的与正则表达式替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Android的字符串。我想换行的4个或更多的连续数字的所有实例与一些HTML。我想这会与正则表达式来完成,但是我有一个很难得到甚至连最基本的规律前pressions工作。
有人可以帮助我?
我想改变:
VAR输入=我的电话是1234567890和我的办公室是7894561230;
要
VAR输出=我的手机为< U> 1234567890< / U>和我的办公室为< U> 7894561230< / U>中;
解决方案
这将做到这一点:
字符串输入=我的电话是1234567890和我的办公室是7894561230;
字符串的正则表达式=\\\\Ð{4};
字符串输出= input.replaceAll(正则表达式,< U> $ 0℃; / U>中);
的System.out.println(输出);
I have a string in Android. I would like to wrap all the instances of 4 or more continuous digits with some html. I imagine this will be done with regex, but I have a hard time getting even the most basic regular expressions to work.
Can someone help me with this?
I would like to change:
var input = "My phone is 1234567890 and my office is 7894561230";
To
var output = "My phone is <u>1234567890</u> and my office is <u>7894561230</u>";
解决方案
This will do it:
String input = "My phone is 1234567890 and my office is 7894561230";
String regex = "\\d{4,}";
String output = input.replaceAll(regex, "<u>$0</u>");
System.out.println(output);
这篇关于Android的与正则表达式替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文