-1

I have a string in the following format:

ABC12233434343DEF

How can I extract only:

ABC12233434343

I want to leave out the ending set of characters of whatever length they might be.

tushaR
  • 3,083
  • 1
  • 20
  • 33

1 Answers1

0

There are several ways this is one:

.*?\d+

It will match anything at the beginning that is followed by numbers.

It may be also posible to limit the characters it can match initially, like if you was capital letters from A-Z, for example:

[A-Z]+\d+

Online Demo

Dalorzo
  • 19,834
  • 7
  • 55
  • 102
  • If I am not wrong, `?` is used to make it non-greedy? – tushaR Sep 15 '20 at 04:33
  • yes takes the greedy behavior in the expression and reduce the steps. The 2nd expression is more efficient but it depends on the limitations you may add – Dalorzo Sep 15 '20 at 04:34