Whats the regular expression for a colon separated value?

落爺英雄遲暮 提交于 2019-12-12 03:44:45

问题


If I have a string such as:

blah blah item: value blah blah

What would the expression be to just get value?


回答1:


You can use this regex

:\s*(\w+)

$1 or group 1 has the required value


\s* matches 0 to many spaces

\w+ matches 1 to many characters which can be any 1 of [a-zA-Z\d_]




回答2:


The regular expression would be

:

As in,

String value = yourString.split(":")[1].split(" ")[0]



回答3:


for your exact String, using **String.split()**

String s="blah blah item: value blah blah";
System.out.println(s.split("(:\\s+)")[1].split("\\s")[0]);

Output: value


来源:https://stackoverflow.com/questions/13727892/whats-the-regular-expression-for-a-colon-separated-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!