Doubt with Regular Expression

Hello everybody!
I have a question with regular expressions; I am trying to obtain the pattern for the examples:

9620314387631 LGF.pdf
9620252215751 NOV.pdf

and I have gotten a match → ^ [9]+\d{12}+[ ]+\w{2}[A-Za-z].pdf (in the web checker regex101.com), but this same pattern is not validated in the web checker regexr.com (error with the + signs; I have tried replacing +[ ]+ with \s , but it does not detect the pattern either. This web always works for me).

It doesn’t work in my project either and I don’t quite understand how to get it.

Thanks in advance!

Hi @mbercianop

Try this regex:
\d+\s\w+.pdf
or
\d{13}\s\w{3}.pdf

image

Use https://regexr.com/ website for regex.

Hi,

I think the pattern should be as the following.

^9\d{12} +\w{2}[A-Za-z]\.pdf

Can you check if you set .net(C#) mode in regex101?

Regards,

1 Like

Hi @mbercianop

\d{9,}\s[A-Z|a-z]+\.[A-Z|a-z]+

@mbercianop

System.Text.RegularExpressions.Regex.Match(InputString,"\d{8,}\s[A-Z]{3}\.[a-z]+").Value

Hi @mbercianop

\d{9,}\s[A-Z|a-z]+\.[A-Z|a-z]+


Hope it helps!!

Hi @mbercianop

Simply use the below one

\d{12}\s+[A-Z]+.pdf

Select the multiline option in Flags dropwdown,

Hope it helps!!

Hi @mbercianop

^[9]+\d{12} \w{2}[A-Za-z].pdf

Regexr
image

Regex101

works fine in both websites.

Regards

@mbercianop
you got several working solutions, so you can choose best one for you :slight_smile:

My proposal:
^9\d{12} \w{3}.pdf

Hi @mbercianop

How about this?

[9]\d{12}\s+\w+\.pdf

image

Cheers!!

Thank you all. It was also my lack of knowledge of configuration by not selecting C# (@Yoichi) and multiline (@mkankatala ).

They all work correctly.

Have a great day!!

1 Like

I hope you got the solution for your query. If yes make my post mark as solution to close the loop.
If you have any further queries, happy to help.

Happy Automation!!

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