SPUG: The Regexp of Infinitude.

Ken McGlothlen mcglk at serv.net
Fri Aug 6 17:33:28 CDT 1999


For reasons which, I'm afraid, are going to be obscure at the moment, I have
the following line in my Perl script:

	$buffer =~ m#^(\043(.*?[^\\])*?)(\043/\})(.*)#s;

Basically, this should be interpreted as

	Starting with the beginning of a multiline string, a group consisting
	of "#" followed by zero or more groups of any characters that do not
	end with a backslash, followed by a group consisting exactly of "#/}",
	followed by a group containing the rest of the string.

Another way to look at this would be

	Starting with the beginning of a multiline string, a group consisting
	of "#" followed by zero or more groups of any characters, followed by a
	group consisting exactly of "#/}" which is NOT preceded by a backslash,
	followed by a group containing the rest of the string.

In other words, I'm working on a program which parses a configuration file.
Its comment syntax (again, for obscure reasons) is

	{# comment text #/}

So I'm working on a state machine that has, at this point of the program,
already trimmed the beginning brace, and now is trying to collect the rest of
the comment.  HOWEVER, the following should be legal:

	{# End comments with the (ignore the backslash) "\#/}" string #/}

Seems to me that the regexp should work, but I can't tell---Perl takes pretty
much forever to run that regexp.

Is there a more efficient way of writing this, or do I really need to take a
completely different approach?  (I'd hate to have to do this in lex and yacc.)

Thanks.

							---Ken

P.S.  Anyone looking for Perl subcontracts?

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list