检查并匹配String列表并替换为特定值

时间:2016-06-12 06:30:35

标签: java

我确实有一些像......这样的随机消息。

Please conform to regex ^[0-9]*$ with a maximum length of 13
Please conform to regex ^[a-z]*$ 
Please conform to regex (?:\\d*\\.)?\\d+ with a maximum length of 999
(and many more...)

如何用

替换这些正则表达式字符串
'Only number' when '^[0-9]*$' appears 
'Only lower case' when '^[a-z]*$'appears
(and so on... ?)

1 个答案:

答案 0 :(得分:0)

我们说你有String str = "...";。您可以使用以下String类方法:

if(str.contains("somethingYouWantReplaced")
    str.replace("somethingYouWantReplaced", "newValue");

另外,请查看:

查看String.ReplaceAll(String Regex, String replacement)