-1

I need to capture the string ||EPB|| and |TRN| but only if they appear as a pair.

My text looks like this.

||EPB|| 1-2-3 |TRN| ||EPB||....||EPB|| Other text ||EPB|| 11-2-3 Test A |TRN| more text that may have carriage returns in it ||EPB||nospace/here||EPB|| 12-2-3 |TRN|

I want the results to be:

  • 1-2-3
  • 11-2-3 Test A
  • 12-2-3

The closest I got was \|\|EPB\|\|(.*?)\|TRN\| But that doesn't handle the situation where there is more than one ||EPB|| appears before a |TRN|

1 Answers1

-1

My solution though not perfect is better than the closest you got above.

(?<=||EPB||)(.*?)(?=|TRN|)

It attempts to "wrap" your string between a positive look behind assertion (match ||EPB|| but nothing before it) and a positive look ahead assertion(match |TRN| but nothing after it).

For a regular expression cheat sheet: https://cheatography.com/davechild/cheat-sheets/regular-expressions/

zimbozim
  • 1
  • 2
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 10 '21 at 04:41
  • edited again to be more explanatory. – zimbozim Nov 24 '21 at 21:53