Extracting Segments Around PO Using REGEXP Functions
Published September 21, 2025
By Sai Sree Ram Gundepudi
Sometimes strings contain identifiers like PO12345678 within larger text. We can extract these segments using REGEXP_REPLACE, REGEXP_INSTR, and SUBSTR.
SELECT TRIM(SUBSTR(REGEXP_REPLACE('INV#8674767JSDEPOSIT DBCD PO DPO12345678 ASASADSDSS', '#|PO', ''),
REGEXP_INSTR('INV#8674767JSDEPOSIT DBCD PO DPO12345678 ASASADSDSS', 'PO'),
INSTR('INV#8674767JSDEPOSIT DBCD PO DPO12345678 ASASADSDSS',' ',1,1) - 1 -
REGEXP_INSTR('INV#8674767JSDEPOSIT DBCD PO DPO12345678 ASASADSDSS', 'PO') - 1)) AS seg_1
FROM dual;This extracts the portion immediately after PO. You can repeat with different INSTR positions for seg_2, seg_3, etc.