Regex activity

I’ve got the various Strings like this “via 25 aprile 123 a” or “via 25 aprile 123a” or “via roma 123” and I want to get all the character from the last number to the end, so in the first case the result should be “123 a”, in the second case “123a”, in the third “123”.

please, Could you help me, i try with regex activity, but i couldn’t find the right expression.
thanks

Here’s a sneaky way to do it. Take your string, and reverse it (see below for the reverse method). Then use this regular expression: [^\d]+\d+. Then reverse the regex string to get the final result.

If your text is all in one file with newlines separating it, you’ll want to split the data at the newlines and do this for each line to get the data you want.

Hello @Alessandro_Rocco

please try the following:

pattern = "\d+\D*$"

i understand the solution but i have some problem to writing this, can you help me?

i try with this solution, but it gave me an error:
System.Text.RegularExpressions.Regex.Match(indirizzo_intero,"\d+\D*$")

Add .Value to the end of the right-hand side of the Assign statement for capovolto. I think that’ll solve the problem.

1 Like

no error again

image

Sorry?

Try to never use variables of generic type, make it String and after the .Value add .ToString as well, but note that if the digit is not found in your string, you will get an exception…

1 Like

@bcorrea agree with you but please note that a Match.Value is already a String then .ToString is unnecessary.

1 Like

works with System.Text.RegularExpressions.Regex.Match(indirizzo_intero,"\d+\D*$").value making “capovolto” a string

thanks to all

1 Like

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