问题
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