Get text from string

Hi There,
I need to extract part of this string, i have looked through the forum and cannot find any suggestions for extracting text where there is not much consistency with the data:

I have text which looks like this:
PAY-TEST PAYMENT 00000000 JOHN SMITH M3000111111
DEPOSIT ONLINE 2121212 PYMT TONY TEST M3000222345
DEPOSIT ONLINE 2648975 PYMT TEST NAME M3000369785
OTHER TEXT TEXT TEXT REF NO 0123456 MELB TEXT REF: M5000789456

From each line of text I only need to extract the numbers after the letter M, i,e from M5000789456 I only need 5000789456

Each line is always different, the numbers/reference number i need to extract are almost always at the end of the string, most times there is no other text after these numbers.

The only things which are always the same:
Each string will have a reference number which will always start with M
Each reference number will always start with M and proceed with either the number 3 OR 5

Can i please get some assistance as the best way to get this reference number?

Thanks

You can try the following regex: (?<=M)(?:3|5)\d*

Try this one in a Matches activity:
Regex Pattern: (?<=M)(3\d*|5\d*

1 Like

Thanks so much - i believe it worked.
I have never worked with ‘Matches’ before. I will play around and get more familiar with it.
Thanks again!

Please use the following to obtain an array of string

Assign (Array of String)
result = System.Text.RegularExpressions.Regex.Matches(myString, "(?<=\bM)[35]\d+").OfType(Of Match).Select(Function(m) m.Value).ToArray

1 Like

Use a write line activity to show the outputs: :slight_smile:
OUTPUTVARIABLE(0).Tostring

Replace the capitals in the above with the variable output from the Matches activity.

1 Like

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