RegEx Letter number pattern question

Hi All,

Please help me with Regex for the following scenario.

" My name is ABC and my id is ABC16552"

How to get combination of alphabets and numeric values ?

Thanks in advance.

1 Like

You can use the Regex pattern [A-Za-z]+\d+ to extract combinations of alphabets and numeric values from the text.

@Pavan_kumar15

If it is at the end of the sentence always then you dont need regex…you can use split as below

Str.Trim.Split(" "c).Last

Cheers

1 Like

Hi @Pavan_kumar15

Assign-> Input = "My name is ABC and my id is ABC16552"

Asdign-> Output = System.Text.RegularExpressions.Regex.Match(Input,"[A-Z]+[0-9]+").Value.Trim()

Hope it helps!!

1 Like

Hi @Pavan_kumar15

Assign-> Input = "My name is ABC and my id is ABC16552"

Assign-> Output = System.Text.RegularExpressions.Regex.Match(Input,"[A-Z]+[0-9]+").Value.Trim()

Check the below image for better understanding

Regards

1 Like

Hi @Parvathy ,

It is working for the above case.

case 1: My name is ABC and my id is ABC16552dd
case 2 :My name is ABC and my id is 16552ddABC
case 3: My name is ABC and my id is abc16552dd

Can you provide Regex expression for the above cases as well ?

Thanks in advance!!
Pavan

1 Like

Hi @Pavan_kumar15

Try this
(?<=my id is\s)[A-Za-z0-9]+

Regards

1 Like

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Match(yourString,"\b[A-Za-z0-9]*([0-9][A-Za-z]|[A-Za-z][0-9])[A-Za-z0-9]*\b").Value

image

Regards,

2 Likes

Hi @Pavan_kumar15

Assign -> Input = "My name is ABC and my id is ABC16552dd
                   My name is ABC and my id is 16552ddABC
                   My name is ABC and my id is abc16552dd
                   My name is ABC and my id is ABC16552"

Assign -> Output = System.Text.RegularExpressions.Regex.Matches(Input,"(?<=my id is\s)[A-Za-z0-9]+",System.Text.RegularExpressions.RegexOptions.Multiline)

Log Message -> String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Input is of DataType System.String.
Output is of DataType System.Collections.Generic.IEnumerable(System.Text.RegularExpressions.Match).

Hope it helps!!

1 Like

Hi @Parvathy ,

It works. Thanks for your help.

What if ‘ABC123’ alone is available. How can we retrieve ?

Thanks in advance.
Pavan.

Hi @Pavan_kumar15

The same regular Expression will work.
Regards

1 Like

Thanks for your help @Parvathy

1 Like

You’re welcome @Pavan_kumar15

Happy Automation!!

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