Extracting substring from a string

Hi team ,

I want to extract “WEF0399876” from below examples -

  1. FW: Fw: PCI SSC Invoice Enclosed - WEF0399876
  2. aiagfajk asdh-jkkWEF0399876ds
  3. FW: Fw: PCI SSC Invoice Enclosed - fsdfsWEF0399876 fwfggwg
    basically WEF+“all integers till a space or non-integer comes”

this should not work for

4.FW: Fw: PCI SSC Invoice Enclosed - fsdfsWEFL0399876 fwfggwg
5.FW: Fw: PCI SSC Invoice Enclosed - fsdfsWEF023WEF0399876 fwfggwg (two WEFs in the same line)\

Regards,
Gokul

IF there is exactly 1 occurrence of WEF with a digit immediately after it, then extract the value. Else, there is either more than one WEF value, or it’s an invalid WEF (ie it doesn’t have a digit right after it “WEFL0399876”)

The regex expression in the Log Message is:

System.Text.RegularExpressions.Regex.Match(item,“(WEF[0-9]{7})”).ToString

Which will find WEF with 7 digits after it.

Here is an example output:

image

1 Like

Hey @gokul1904

You can start to learn Regex using my Regex MegaPost :blush:

Cheers

Steve

2 Likes

Hi ,

There is no criteria of only 7 digits after WEF. It should pick up all the integers after WEF till a space/alphanumeric/non-integer value comes.

So can you please help me in modifying this -
System.Text.RegularExpressions.Regex.Match(item,“(WEF[0-9]{7})”).ToString

Regards,
G

Then just remove the 7 limitation and replace it with +

System.Text.RegularExpressions.Regex.Match(item,“(WEF[0-9]+)”).ToString

Hi @gokul1904

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(WEF\S\d{6,7})").Tostring

image

Regards
Gokul

Thank you , Will it pick up WEF048421135?

Hi @gokul1904

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(WEF\S\d{6,9})").Tostring

image

Regards
Gokul

How many digit will appear after WEF ?

its not constant.its dynamic.but it is

WEF(all integers till a noninteger/space comes)

Hello

Please try this:
System.Text.RegularExpressions.Regex.Match(item,“(WEF\d+)”).ToString

Cheers

Steve

1 Like

thanks a lot

Hi @gokul1904

This Patten will get WEF023 also in the input. How this will work for you? Have you handle with any kind of method?

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(WEF\S\d{6,15})").Tostring

(WEF\S\d{6,15} → In this Expression you can change 15 into 100 so on. It will depends on the integer after WEF.

image

Regards
Gokul

Ahhh @Gokul001 good pickup! I have missed that example, I wondered why everyone was overlooking that pattern :sweat_smile:

@gokul1904 - Lets try again to help you. You could try this pattern.

Or you could try one the above methods offered by @Gokul001 in their post. Otherwise, some more information / samples if they are not working.

Hopefully you have a pattern otherwise we will keep working on a pattern :blush:

Cheers

Steve

Hi @gokul1904

How about this expression?

System.Text.RegularExpressions.Regex.Match(YourString,"(WEF\S\d+)(?=\s)|(WEF\S\d+)(?=[a-z])").Tostring

Regards
Gokul

1 Like

Hey @Gokul001

That could work but options 4 and 5 are not supposed to match - but can be with your pattern :slight_smile:

Up to @gokul1904

Cheers

Steve

1 Like

Hey Gokul , that was a mistake from my end.I did not test the last 2 scenarios . Thanks for pointing it out.Now its resolved.

Thank you for all your efforts and inputs

Regards,
Gokul

Cool - glad you have your answer :slight_smile:

If Option 4 isn’t supposed to match but Option 5 ideally is then take a look here.

Cheers

Steve

1 Like

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