1

Here is the sample data from a JBehave story that I want to extract from:

And we validate that the following occurrences for event 123456 and source PLAYER are saved in Database:
| PLAYER | GAME     | 
| 1      | FOOTBALL |

And we validate that the following messages for event 123456 and source PLAYER are sent in Other Database:

Using the fixed phrase:

 And we validate that the following occurrences for event 123456 and source PLAYER are saved in Database:

I want to use that sentence as the starting point of my search and get everything up until the next word And

Expected Output:

And we validate that the following occurrences for event 123456 and source PLAYER are saved in Database:
| PLAYER | GAME     | 
| 1      | FOOTBALL |

I have tried the following expression:

\w*:[^And]*

However, I haven't figured out the part where I match using the fixed phrase.

Loren
  • 1,260
  • 5
  • 16
  • 23

1 Answers1

1

You may use

.*:(?s).*?(?=\bAnd\b|$)

See the regex demo

Details

  • .* - any amount of any chars other than line break chars, as many as possible
  • : - a colon
  • (?s) - now, all . to the right will match any chars including line break chars
  • .*? - any amount of any chars other than line break chars, as few as possible
  • (?=\bAnd\b|$) - a positive lookahead that ensures there is a whole word And or end of string immediately to the right of the current location.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563