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.

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

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!!

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

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

Hi @Pavan_kumar15

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

Regards

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,

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!!

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

Thanks for your help @Parvathy

You’re welcome @Pavan_kumar15

Happy Automation!!