in reply to how can I combine these expressions?

Why not just stick a ? after each brace? That means 'match zero or one times'. I don't see anything different that happens if the variable's braced, but my brain hurts today so definitely test it first. :)

Update: Okay, the quick-correcting Ovid and lhoward point out the unbalanced problem. The only other thing I can think of is an alternation: (?:{([_a-zA-Z]\w*)}|([_a-zA-Z]\w*)) That part obviously goes after you've found the % sign. It will be more expensive, though. (The * operator hurts.)

Replies are listed 'Best First'.
(Ovid) RE(2): how can I combine these expressions?
by Ovid (Cardinal) on Jul 27, 2000 at 03:02 UTC
    chromatic: sticking a ? after each brace would still allow mismatched braces to be passed through. Since this is user supplied data, I can see a potential for a lot of typos.

    Cheers,
    Ovid