Prev: FAQ 4.1 Why am I getting long decimals (eg, 19.9499999999999) instead of the numbers I should be getting (eg, 19.95)?
Next: FAQ 3.24 Why don't Perl one-liners work on my DOS/Mac/VMS system?
From: Mark Hobley on 25 Jul 2010 15:19 I need a regular expression with the following properties. I need to match text (typically, though not necessarily expressions) enclosed within double parentheses. However, I do not want to match nested single parentheses enclosed text. So ((*)) is a match, but ((*)*(*)) is not a match. Here are some examples to illustrate this. ((FOO)) - This is a match (()) - This is a match ((3 + 2)) - This is a match ((3 + 2) + (2 * foo)) - This is not a match ((3 * bar) + ((foo))) - This is a match ((3 * bar) + ((foo))bar) - This is a match. I hope that lot makes sense. Thanks in advance to anyone who can help. -- Mark Hobley Linux User: #370818 http://markhobley.yi.org/ --- news://freenews.netfront.net/ - complaints: news(a)netfront.net ---
From: Peter J. Holzer on 25 Jul 2010 16:04 On 2010-07-25 19:19, Mark Hobley <markhobley(a)yahoo.donottypethisbit.co> wrote: > I need a regular expression with the following properties. > I need to match text (typically, though not necessarily expressions) > enclosed within double parentheses. However, I do not want to match nested > single parentheses enclosed text. > > So ((*)) is a match, but ((*)*(*)) is not a match. > Here are some examples to illustrate this. > > ((FOO)) - This is a match > (()) - This is a match > ((3 + 2)) - This is a match > ((3 + 2) + (2 * foo)) - This is not a match > ((3 * bar) + ((foo))) - This is a match > ((3 * bar) + ((foo))bar) - This is a match. Is this a match? (((1 + 2) * (3 +4))) hp
From: Ben Morrow on 25 Jul 2010 18:29 Quoth Mark Hobley <markhobley(a)yahoo.donottypethisbit.co>: > I need a regular expression with the following properties. > I need to match text (typically, though not necessarily expressions) > enclosed within double parentheses. However, I do not want to match nested > single parentheses enclosed text. > > So ((*)) is a match, but ((*)*(*)) is not a match. > Here are some examples to illustrate this. > > ((FOO)) - This is a match > (()) - This is a match > ((3 + 2)) - This is a match > ((3 + 2) + (2 * foo)) - This is not a match > ((3 * bar) + ((foo))) - This is a match > ((3 * bar) + ((foo))bar) - This is a match. Is there something wrong with /\(\([^(]*\)\)/ ? (Hmm, that's *seriously* unreadable.) Ben
From: Jens Thoms Toerring on 25 Jul 2010 18:36 Mark Hobley <markhobley(a)yahoo.donottypethisbit.co> wrote: > I need a regular expression with the following properties. > I need to match text (typically, though not necessarily expressions) > enclosed within double parentheses. However, I do not want to match nested > single parentheses enclosed text. > So ((*)) is a match, but ((*)*(*)) is not a match. > Here are some examples to illustrate this. > ((FOO)) - This is a match > (()) - This is a match > ((3 + 2)) - This is a match > ((3 + 2) + (2 * foo)) - This is not a match > ((3 * bar) + ((foo))) - This is a match Should the whole thing be the match or only the "((foo))" part? > ((3 * bar) + ((foo))bar) - This is a match. Same question here > I hope that lot makes sense. If in e.g. "((3 * bar) + ((foo)))" only the "((foo))" part is meant to be the match then I would think \(\([^(]*\)\) should do the job - you seem to want two opening parentheses, followed by some text that does not contain another opening parenthesis, and finally two closing parentheses. Regards, Jens -- \ Jens Thoms Toerring ___ jt(a)toerring.de \__________________________ http://toerring.de
From: Ilya Zakharevich on 26 Jul 2010 02:51
On 2010-07-25, Ben Morrow <ben(a)morrow.me.uk> wrote: > Is there something wrong with /\(\([^(]*\)\)/ ? > > (Hmm, that's *seriously* unreadable.) Today, I ruined one of my most beautiful RExes: qr{([<>])} for parsing POD. To treat mismatched < and >, one actually needs to through in \z as well. What is the moral? I do not know! m{\(\([^(]*\)\)} is not better, right? Fontification by CPerl helps a little bit, of course, but not much. Lisp has the notion of "escaping out of quoting"; so it would look something like m{ (( (?` [^(]* ) )) }xq assuming //q means /\Q/, except that the part inside (?` ) is not quoted... Yours, Ilya |