-1

I am trying to extract a version and need to match on a third variant as shown here:

ersion ([^,]*)(,)? RELEASE

Need to match on:

Version 03.06.07b.E, RELEASE SOFTWARE (fc1)
Version 03.06.07b.E RELEASE SOFTWARE (fc1)
version 1.3(2)ES3

Match fails on the third row.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
dross
  • 1,719
  • 2
  • 14
  • 22
  • How about `ersion (?:([^,]*)(,)? RELEASE|.*)`? Your question is i poor shape since it is not clear what is allowed/not allowed for the 3rd match. It is not well specified. – Micha Wiedenmann Feb 09 '18 at 08:19
  • 1
    Possible duplicate of [Learning Regular Expressions](https://stackoverflow.com/questions/4736/learning-regular-expressions) – Biffen Feb 09 '18 at 08:20
  • 2
    Try [`/Version ([^,]*)(?:,? RELEASE)?/i`](https://regex101.com/r/rAnhMq/1), but it seems you do not even need `(?:,? RELEASE)?` if you want to extract just what `([^,]*)` captures. [`/Version\s+([^,\s]*)/i`](https://regex101.com/r/rAnhMq/2) might be all you need. – Wiktor Stribiżew Feb 09 '18 at 08:20
  • Also: "Version 03.06.07b.E RELEASE SOFTWARE (fc1) RELEASE" will match your regex". – Micha Wiedenmann Feb 09 '18 at 08:22

1 Answers1

2

The third string is not matched because it does not contain the required RELEASE substring.

It seems all you need to match is any 0+ chars other than whitespace before the , char and after Version substring.

Use

/Version\s+([^,\s]*)/i
(?i)Version\s+([^,\s]*)

See the regex demo.

The Version will match version, too, due to the case insensitive flag, \s+ matches 1+ whitespaces and ([^,\s]*) will capture 1 or more chars other than whitespace and ,.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563