1

If I have a string such as:

blah blah item: value blah blah

What would the expression be to just get value?

dan1st
  • 12,568
  • 8
  • 34
  • 67
carboncomputed
  • 1,630
  • 3
  • 20
  • 42

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
  • 32,393
  • 7
  • 68
  • 89
4

The regular expression would be

:

As in,

String value = yourString.split(":")[1].split(" ")[0]
Johan Sjöberg
  • 47,929
  • 21
  • 130
  • 148
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
PermGenError
  • 45,977
  • 8
  • 87
  • 106