我想在 Java 中使用正则表达式来提取具有以下属性的子字符串:
- 子字符串以“WWW”开头
- 子字符串的末尾是冒号“:”
我在 SQL 方面有一些使用 Like 子句的经验,例如:
Select field1 from A where field2 like '%[A-Z]'
因此,如果我使用 SQL,我会编写代码:
like '%WWW%:'
如何在 Java 中启动它?
最佳答案
Pattern p = Pattern.compile("WWW.*:");
Matcher m = p.matcher("zxdfefefefWWW837eghdehgfh:djf");
while (m.find()){
System.out.println(m.group());
}
关于java - Java 中的正则表达式字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13106431/