Formatted Search with Substitution Patterns
In
MultipleSearchesInSameTopic,
AmitTendulkar and
VinodKulkarni suggest to define variables
$1,
$2,
$3 etc instead of a single
$pattern. These variables correspond to Perl's usual mechanisms to select specific segments of a pattern match.
I really like the idea of supporting a substitution pattern. That is a very flexible way to grab more then one thing out of a text and format the result. What is a good syntax?
$substitute(pattern/replace) or what else?
Example: Get the Name and Email from a home page and format it as a table row:
$substitute(.*?\* Name\:([^\n\r]*).*?\* Email\:([^\n\r]*).*/|$1|$2|)
The question is to find a good syntax for
$substitute(pattern/replace) which is intuitive, flexible and is easy to parse. Questionable syntax indicated in red. What if I want to use a slash in the pattern; or a closing parenthesis in the "replace" part? We could support multiple delimiters like in Perl.
--
PeterThoeny - 27 Sep 2003
Ideas for syntax:
-
$substitute(pattern/replace)
-
can't use slash in pattern or replace
-
no reliable way to parse for closing parenthesis
-
$substitute({pattern}{replace})
-
safe to parse
-
syntax known to Perl programmers
-
$substitute(<pattern><replace>)
-
safe to parse
-
syntax known to Perl programmers
--
PeterThoeny - 24 Feb 2004
or:
-
$substitute(/pattern/replace/) (where "/" can be any character)
-
safe to parse
-
syntax known to Perl programmers
How hard would it be to use the
entire perl substitution syntax? Can't you just stick whatever is in the brackets after an "s"?
--
SamHasler - 24 Feb 2004
can i get out my featuritus flag, and indicate that this sounds like techy plugin land? (yes its easy to do and feels sexy, but should it really be done?)
--
SvenDowideit - 24 Feb 2004