简体   繁体   English

正则表达式使模式中的单词

[英]Regex to get a word in a pattern

I don't know how best to word this. 我不知道该怎么说最好。 I have a set of patterns: Usa-Texas Usa-Chicago USa-Washinton . 我有一组模式:美国-德克萨斯州美国-芝加哥美国-华盛顿州。 . Usa-{some USA state} 美国-{某些美国州}

Now, I need a regex(java) to extract only the USA. 现在,我需要一个regex(java)仅提取美国。 I am just wondering why this didn't work : "(//busa//b)" It wasn't extracting the USA.. 我只是想知道为什么这行不通: "(//busa//b)"那不是在提取美国。

use this to fix the problem. 用它来解决问题。

 Pattern p = Pattern.compile("\\bthis\\b");
 Matcher m = p.matcher("Print this");
  m.find();
 System.out.println(m.group());

Output: 输出:

this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM