How to get the first numeric from the string

I have a string like :
Article 1404565001 für Unterputz-, Spülkasten Nr. 240.705
string : Aufputz Spülkasten AP140 für 2-Mengen-Spülung, Toilettenspülung tief hängend, mit flexiblem Wasseranschluss, geräuscharm, weiß, Art.Nr. 140300111

I need just 1404565001 or 140300111

So need to get first numeric with a length > 5 digit

Try This:

TestDev.xaml (6.7 KB)

to get only the first numeric with length greater than 5, just remove the for each and test by write line:

thank you for your solution …but i can’t fix yet my string come from an assign : row.Item(“Tit”).ToString

I’d recommend using regex. The following put into an assign will return an integer (requires tweaks if you want decimals/doubles)

Assign MyInteger = Cint(System.Text.RegularExpressions.Regex.Match(InputText,"\d{5,}").Value)

This searches the string (i named InputText) for 5+ digits in a row and grabs the first one it finds

1 Like

This is a solution ,thank you . But now i realise that some numbers are like 234.343.3.42 and this kind of number are not included in this regex. How can i fix to remove dots and to include this numbers too ?

You still want it to be 5 numbers though, right? So 234.34 would be found, but 234.3. should not be found, correct?

i have to check to find first numberic in string with more than 5 digit , and if contain dots like 23.345.34.3 to return 23345343

I’m struggling to think how to do the count portion when there are an unknown number of . characters that could be found in between the digits. @Steven_McKeering perhaps you have an idea?

I do know that once you get your string returned that could include the .character, you can just do a simple .replace() to fix it. This works even if there were no . in the returned string. So if MyString = or MyString = 234532 both would return 234532 when you do MyString = MyString.Replace(".",string.empty)

1 Like

Not sure why I didn’t think of this previously, but you can flip the order and do the string.replace first, then do your regex :slight_smile:

So step 1 = assign MyString = Mystring.Replace(".",string.empty)
step 2 = use the regex I posted previously

Note that if you need to use MyString as-is for reasons other than this, then you should create a new string in step 1 rather than changing the existing string


System.Text.RegularExpressions.Regex.Match(Tit,"[0-9]+(.[0-9]{1,10})?(.[0-9]{1,10})?(.[0-9]{1,10})").Value i used this expresion and seems is working . Thank you for your help

1 Like

I would highly recommend my latest commented solution instead as it’s a bit easier to read and understand (I can’t follow how the count portion is working in your latest regex). But as long as it is working then no worries :slight_smile:

EDIT: The solution you posted seems to be capturing the numbers even if it is less than 5 digits, and it also captures patterns such as 2.3.65 even though that’s only 4 digits long

1 Like

Hi @uiNew

As per @Dave’s reply -

The pattern you suggested will give you incorrect results.

You need to follow @Dave suggested solution complete two steps (replace all “.” with “”)

Then apply a Regex pattern for digits greater than 5.