Front page | perl.perlfaq.workers |
Postings from January 2005
From: Paul Apostolik
January 6, 2005 13:49
Message ID: 41DDA1F9.email@example.com
While looking for information relating to regular expressions I
came across the following:
The perlfaq6 manpage: Regular Expressions
The regular expression given to match C style multi-line
comments is 72 characters long and very poorly reasoned out. I
would like to present you with a much more concise alternative:
The first step in working this problem will be to say exactly
what a comment is in english:
A comment starts with '/*', ends with '*/' and contains
no '*/' in the middle.
Matching the begining and ending seems simple enough - '/*'
and '*/' accomplish this task. It is the middle that poses some
difficulty. The regular expression needs to esure that if it
ever consumes a '*' then the following character is not a '/'.
So we can pass anything that is not a '*' without concern -
'[^\*]*'. If we do see a '*' then the next character must be
anything but a '/' - '(\*[^/])*'.
Putting that all together gives us the regular expression we
1) allows 0 or more instances of either 2) or 3)
2) allows non-star chars to pass
3) requires any star char to be followed by a non-slash char
You may use any part of this message in the perlfaq provided
you do not publish my email address.
The generation of random numbers is too important to be left to
by Paul Apostolik