How to save multiple values from a text with only one Regex Builder

I want to extract value after RUC:, Fecha de Emisión:, Señor(es): in differents variables string using only one Regex builder is it possible?

@"SCOTIABANK PERU SAA
RUC: 20100043140
Comprobante de Pago

AV. DIONISIO DERTEANO 
Teléfono.211-6000
Nro. FC02-001521

Señor(es): EQUINOX INTERNATIONAL

Dirección: AV. JOSE LARCO 1

DNI: 20422488198 Moneda: SOLES

Fecha de Emisión: 07/10/2022

DESCRIPCIÓN VALOR VENTA TOTAL IGV PRECIO VENTA TOTAL

Comisi�n 20.00 0.00 20.00

SON: VEINTE CON 00/100 SOLES

Información Adicional: Sub Total 20.00

PRODUCTO CUENTAS CORRIENTES I.G.V. 0.00

Importe Total 20.00

Fecha y Hora de Autorización: 07/11/2022 17:47

Autorizado mediante resolución Nro. 0340050010017/SUNAT. Representación impresa del Comprobante Electrónico."

Hi @odelacruz

You can…
If you know the prder is same always…then just use | this pipe symbol to give multiple regex that you want to find

Eg : system.text.regularexpressions.regex.matches(“A Ball is cool”,”A|B|C”) will return A , B and C present in the string

So you can build 3 different regex for the three fields you need and send them with a pipe and you would get all 3 values

Then you will get one match array variable containing all 3 values

Cheers

Hello @odelacruz,
yes it is possible to do with one match only by using groups and specific start and end keywords.
But to go with @Anil_G it is more readable if you split the regex match up in three parts.

Please find a one-match solution here: regex101: build, test, and debug regex

(!) very important: set the RegexOptions to Singleline, otherwise it won’t work.

Regards

Hi @odelacruz ,

Is this the output you were looking for?
image

If so, then given below is the regex pattern along with a sequence to help you out:

"RUC: (?<RUS>.*)[\s\S]+Comprobante[\s\S]+Señor\(es\): (?<Senor>.*)[\s\S]+Dirección[\s\S]+Fecha de Emisión: (?<Emision>.*)[\s\S]+DESCRIPCIÓN"
String.Join(vbNewline,matches_data.SelectMany(Function(sm) Enumerable.Range(1,sm.Groups.Keys.Count-1).Select(Function(i) sm.Groups(i).Name + " : " +sm.Groups(i).Value)))

ExtractDataWithSingleRegex.xaml (6.6 KB)

Kind Regards,
Ashwin A.K

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.