1

Hi I'm new in Regular expression. Please kindly help me to use regex to select SN from text string. I have

Agilent Technologies,86100D,MY53060185,A.10.80

My purpose is to select "MY53060185", I try to using look behind for "," character with this regex

(?<![a-z A-Z0-9])(?<!,)(?<![a-z A-Z0-9])(?<!,)[a-z A-Z0-9]+

So far failed.

I would be appreciated if you can help me. Thanks in advance.

2 Answers2

0

Remove all the lookarounds and use capturing group and start of the line anchor..

^[a-z A-Z0-9]+,[a-z A-Z0-9]+,([a-z A-Z0-9]+)

Now get the string you want from group index 1.

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
0

Assuming your SN ALWAYS starts with MY followed by numbers, the following simple regex will capture it:

/(MY\d+)/

If this is not what you want or doesn't work with a specific scenario, let me know and I can moddify it to accompany any other situation you may have. Hope that helps!

Izzy
  • 272
  • 1
  • 14