What's a regular expression for several occurrences of a string followed by underscore and number?

StackOverflow https://stackoverflow.com/questions/23373746

  •  12-07-2023
  •  | 
  •  

Question

Is there a regular expression that matches several (one or more) occurrences of a specific string followed by underscore and number, followed by single underscore and a completely arbitrary string.

For example, if a specific string is "BLAH", I am looking to extract BLAH_45435_BLAH_6787_BLAH_454335
from
BLAH_45435_BLAH_6787_BLAH_454335_ThisIs_My_name.

It is safe to assume that the whole input does not include empty spaces (it is a name of a Maya object). The language implementation is Mel in Maya.

Was it helpful?

Solution

You can use this regex:

(?:((?:^|_)BLAH_[0-9]+)+)

Working Demo

OTHER TIPS

LIVE DEMO

Try this Regex:

/(BLAH_+|[0-9]+_)+/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top