Tags:
create new tag
, view all tags

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:

  1. $substitute(pattern/replace)
    • frown can't use slash in pattern or replace
    • frown no reliable way to parse for closing parenthesis
  2. $substitute({pattern}{replace})
    • smile safe to parse
    • smile syntax known to Perl programmers
  3. $substitute(<pattern><replace>)
    • smile safe to parse
    • smile syntax known to Perl programmers
-- PeterThoeny - 24 Feb 2004

or:

  1. $substitute(/pattern/replace/) (where "/" can be any character)
    • smile safe to parse
    • smile 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

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2004-02-24 - SvenDowideit
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2015 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.