0

I want to find regular expression pattern to match digits between XYZ_ and first underscore.

Example want to get 2M284904C4 from below string.

 XYZ_2M284904C4_20210201_120032.xyz

I tried XYZ_.*_,but it matches XYZ_2M284904C4_20210201_

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
div
  • 23
  • 5

1 Answers1

1

Try string.split() at the underscores, and then select the item you want from the returned list. For example,

string = 'XYZ_2M284904C4_20210201_120032.xyz'
string_list = string.split('_')
result = string_list[1]
jWhiteside
  • 127
  • 5