0

If I have a string such as:

blah blah item: value blah blah

What would the expression be to just get value?

BenMorel
  • 31,815
  • 47
  • 169
  • 296
carboncomputed
  • 1,548
  • 3
  • 19
  • 38

3 Answers3

8

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_]

Anirudha
  • 31,626
  • 7
  • 66
  • 85
4

The regular expression would be

:

As in,

String value = yourString.split(":")[1].split(" ")[0]
Johan Sjöberg
  • 46,019
  • 20
  • 127
  • 142
2

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
PermGenError
  • 45,111
  • 8
  • 85
  • 106