|
Posted by Toby A Inkster on 10/14/41 12:00
elmosik wrote:
> Multi line comments:
> '@/\*.*?\*/@ims'
>
> Hashed lines:
> '@^[\s|\t]+#.*?$@ims'
>
> Double slashed lines:
> '@^[\s|\t]+//.*?$@ims'
Regular expressions simply do not cut it. Consider the following comments
which will not be caught by your regular expressions:
define('SOME_CONFIG_OPTION', TRUE); # Here is a comment
define('SOME_OTHER_OPTION', TRUE); // Here is a comment
But what about the following code which contains no comments, which will
be treated as comments by your regexs:
$comment = "/* Lala */
// Lala
## Lala
No comments here!";
print $comment;
Regular expressions are no good for any non-trivial parsing task. You need
a stateful parser.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 17 days, 23:36.]
Gnocchi all'Amatriciana al Forno
http://tobyinkster.co.uk/blog/2008/01/15/gnocchi-allamatriciana/
Navigation:
[Reply to this message]
|