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

Domanda

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.

È stato utile?

Soluzione

You can use this regex:

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

Working Demo

Altri suggerimenti

LIVE DEMO

Try this Regex:

/(BLAH_+|[0-9]+_)+/
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top