To get string between 2 text but one of the text is not consistent form

Hi everyone,

I am trying to extract the Model Number which is in highlighted below.
But the issue is the number after Stroke is some times 2 or 4. So I think it will cause an issue if I were to proceed with the below regex:

This is the “Get Text” from the “Preview extraction” in UiPath:

Design: MWM (Group: Caterpillar), Engine Builder: Motoren Werke Mannheim AG (MWM) - Mannheim 1 x TBD645L9, 4 Stroke, Single Acting, In-Line (Vertical) 9 Cy. 330 x 450, Mcr: 3,825 kW (5,200 hp) at 600 rpm

Is there a way around this? I appreciate any kind of help. Thank you

The Model Number is always in between the “x” and the “, 4 Stroke” but the Stroke can sometimes be “, 2 Stroke”

Hi @Irfan_Musa

Input= "MWM (Group: Caterpillar), Engine Builder: Motoren Werke Mannheim AG (MWM) - Mannheim 1 x TBD645L9, 4 Stroke, Single Acting, In-Line (Vertical) 9 Cy. 330 x 450, Mcr: 3,825 kW (5,200 hp) at 600 rpm"
Output= System.Text.RegularExpressions.Regex.Match(Input,"[A-Z]+[0-9]+[A-Z0-9]+(?=,?)").Value

Hope it helps!!

@Irfan_Musa

Please try this

(?<=x ).*(?=, [2,4] Stroke)

if it an be any number then use this (?<=x ).*(?=, [0-9] Stroke)

Hope this helps

cheers

Hi @Irfan_Musa

Try this

(?<=x )([A-Z]+[0-9]+[A-Z0-9]+)(?=,?)

Thank you for the help and the brief explaination.

1 Like

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