in reply to Re: Re: Re: nested pattern matching
in thread nested pattern matching

When I read the OP's example, and the followup solution, I did worry about one thing. Though the OP did show the character classes [XYZ] and [ABC] in his example regular expression, his example test string used exactly those same characters, in the same order. My concern is that it is possible that he intends to match exactly XYZ and ABC (and of course whatever falls between up to 21 characters).

What I'm getting at is that:

/[XYZ]{3}([A-Za-z]{0,21}?[ABC]{3}/g

will match both of the following strings:

"ASDFXYZOtherCharsABCASDF" "ASDFXXXOtherCharsAAAASDF"

If he intended to specifically match XYZ, and not XXX, then he needed the following regexp instead:

/XYZ([A-Za-z]{0,21}?ABC/g

Again, the OP's original regexp confirms that he wanted to match three characters from a class, zero to 21 characters from a class, and then three characters from another class.

But his choice of example strings showed him looking to match three specific characters, followed by zero to 21 characters from a class, followed by three more specific characters.

I just wanted to point out that there is a difference, just in case it turns out to be significant in the implementation planned by the original poster.

Dave

"If I had my life to do over again, I'd be a plumber." -- Albert Einstein