in reply to Creating spacers in regex match

Use alternation to match the exact two substrings you intend to match.

m/\b16 03 01 (?:34 23|39 4b) 0b\b/

This regular expression pattern will only match the two substrings...

    16 03 01 34 23 0b
    16 03 01 39 4b 0b

The word boundary assertion \b ensures you won't wrongly match a substring like 916 03 01 34 23 0bf.

Jim

Replies are listed 'Best First'.
Re^2: Creating spacers in regex match
by muba (Priest) on Jul 09, 2011 at 02:32 UTC

    Alternation sounds good, but only if just 34 23 or 39 4b are accepted. From what I gather from the OP, any two pairs of hexadecimal digits could get there. Alternation really isn't the means to the desired end here.

      Alternation sounds good, but only if just 34 23 or 39 4b are accepted. From what I gather from the OP, any two pairs of hexadecimal digits could get there. Alternation really isn't the means to the desired end here.

      You misread what the OP wrote. Only 34 23 and 39 4b are acceptable.

      I want to be able to match both these strings
      ...16 03 01 34 23 0b.... ...16 03 01 39 4b 0b....

      Alternation is what's needed here.

      Jim

        I don't mean to turn this into some kind of heated debate about nothing, but it's the following line that leads me to interpret this as something for which alterntions aren't suited:

        I was wondering if there was a way to write a match expression like "m/16 03 01 anything anything 0b/".