I wish to extract “2”
(00000002)the from below string. But the condition is that the string should start with *X1. I wish to have a generic regular expression as in if there will any number it should return it.
I have tried this regex –
But it returns number all the strings,
But I wish have from a specific tag e.g. *X1
Any suggestions would be helpful. Thanks.
If you don’t want to use capturing groups, then another valid expression is this one:
([1-9]+[0-9]*), creating a capturing group, you can also leave out the brackets –
[1-9]+[0-9]*, works either way.
The expression allows for anything in front, then some spaces, then capturing the first number, but ignoring 0 prefixes.
You can play around with it and look at the in-depth explainations using the demo here: