Stack Overflow archive
1 scoreaccepted

regex to get particular values from a string

score
1
question views
249
license
CC BY-SA 3.0

You can use ^[^ ]+.

Example:

java
String s = "test179901034102 00:00:00:00:00:01 Open\n" +
    "test179901083723 00:00:00:00:00:01 Open\n" +
    "test179901153595 00:00:00:00:00:01 Open\n" +
    "test179901187836 00:00:00:00:00:01 Open";

Pattern pattern = Pattern.compile("^[^ ]+", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
  System.out.println(matcher.group(0));
}

See: https://regex101.com/r/aZYgvC/1

Originally posted on Stack Overflow. Public user contributions are licensed under Creative Commons Attribution-ShareAlike.