Hello,
I am pretty new to RegEx tool and want to extract the second four-digit in the below string with RegEx.
For example, need "3331" in the blow string:
A:\Bbbb\Cccc\2019\No&Disc\1. In_Out basis \3331 Out Bas Calc.xlsx
Thanks!
Way
Solved! Go to Solution.
Hey @szwgl2022,
Heres one of the ways to do that
The regex below matches against some characters then 4 digits then some characters and finally then looks for our group of 4 digits after that
.+\d{4}.+(\d{4})
I'd recommend regex101: build, test, and debug regex for learning and practicing
Any questions or issues please ask :)
HTH!
Ira
.*(\d{4}).*
is greedy. It finds the last 4 digits.
cheers,
mark
Thank you all for the help! :)
Hi @IraWatt , thanks a lot for your help! There are some of the strings in the same field have a letter or two right after the four digits I need. How do you modify the regex to parse the four digits with the letters?
for example, need to parse out "3331A" and "3331BC"
A:\Bbbb\Cccc\2019\No&Disc\1. In_Out basis \3331A Out Bas Calc.xlsx
A:\Bbbb\Cccc\2019\No&Disc\1. In_Out basis \3331BC Out Bas Calc.xlsx
.*(\d{4}\u*\b).*
is greedy. It finds the last 4 digits and includes any letters.