Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment inside perl regular expression

by vinoth.ree (Monsignor)
on Mar 13, 2009 at 12:44 UTC ( [id://750385]=perlquestion: print w/replies, xml ) Need Help??

vinoth.ree has asked for the wisdom of the Perl Monks concerning the following question:

How do you put comments inside a Perl regular expression?

Replies are listed 'Best First'.
Re: comment inside perl regular expression
by moritz (Cardinal) on Mar 13, 2009 at 12:50 UTC
    With the /x modifier:
    my $re = qr{ "[^"]*" # first quoted string = URL ... # more stuff }x
      Or by doing something really wacky:
      /(?:(*FAIL)\QThis is a comment\E)?PATTERN/
      Not something I recommend doing though.
        If you want inline comments, you can use (?# comment ) instead, which is less wacky, but I still think that it's no great thing in terms of readability.
Re: comment inside perl regular expression
by toolic (Bishop) on Mar 13, 2009 at 13:13 UTC
Re: comment inside perl regular expression
by VinsWorldcom (Prior) on Mar 13, 2009 at 14:07 UTC

    Regex are tough enough to read without inserting comments into them. What's wrong with putting a detailed comment block above the regex explaining what/how it does what it does? That's what I do so when I inevitably go back to modify it at a later date, I don't have to 'learn' regex all over again.

      Compare these 3 I think the 1st one is the easiest
A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://750385]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 18:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found