Home > Net >  Regex capture specific strings in between
Regex capture specific strings in between

Time:01-11

How to capture specific strings in regex. I want to capture for those strings between semi-colon(;) and PV there are similar strings but only for those without letter O after the semi-colon(;). Seems my pattern is lacking. Btw, PHP may vary from time to time.

Pattern: [^O][A-Z]{3}\d.*PV

Dataset in rows.
1. KPTP; PHP10.00    AA ZA; PHP20.00    PV ZB;OPHP1000.00   PV ZC


2. KPTP;OPHP20.00    PV ZA;OPHP20.00    BB AA ZB; PHP500.00   PV ZC    

Desired Result
1. 20.00
2. 500.00

CodePudding user response:

Use lookahead and lookbehind:

(?<=;[^O][A-Z]{3})\d \.\d (?=\s PV)
  • Related