Re: Interaction between two strings

From: Austin P. So (Hae Jin) (haejin_at_ubc.ca)
Date: 11/11/03


Date: Mon, 10 Nov 2003 20:54:20 -0800


Ewout wrote:

> Assume that the parameter value is ABCR. The regex should be such that
> for example a string like ABCC should give a match. But if the
> parameter value is XYZR, then the string XYZC should give a match. To
> summarize: the regex should take part of the pattern from another
> string that is supplied separately from the regex. Is there any way to
> achieve this?

I'm a crappy perl programmer, but I think I understand your problem
despite the fact that you are being very ambiguous about it.

You seem to be doing what many "bioinformaticians" have been trying to
do, which is compare two sequences and find patterns of similarity
between these two sequences....so you might want to look in the bioperl
module (www.bioperl.org).

If you do as you wish and "parameterize" it, you will have to find a
metric and a weighting method which makes it a hard problem...

Otherwise, you could do what I think you are thinking of doing, and you
could generate a set of wild card matches which you could use to regex.
There are obvious memory issues (x**n permutations of x characters of
length n), but one trick is rather than build an array or hash of
$patterns, you splice them all into one very big $pattern.

i.e. $pattern = "x1|x2|x3....|xn";
        $string =~ /$pattern/;

Doing this is immensely faster than iterating through an array or the like:

i.e. foreach $pattern (@pattern){
        $string =~ /$pattern/;

This was mentioned somewhere...Perl Cookbook? Or it may have been the
advanced book of Perl Programming...

Austin



Relevant Pages

  • Re: regular expression question
    ... how would the pattern need look if the name wasn't "" delimited. ... >> into an array of two values. ... > You can use the following RegEx to parse the string: ... > You will not have a match, so yes you will have an empty string returned. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Regex question
    ... structure of the date you're trying to extract. ... For example, in Regex you can ... pattern that will ensure a valid date within the range allowed by T-SQL ... valid date from a string. ...
    (microsoft.public.dotnet.languages.csharp)
  • str.scan
    ... Regexp or a String). ... added to the result array or passed to the block. ... If the pattern ...
    (comp.lang.ruby)
  • Re: regex
    ... case sensitivity was part of the problem which I fixed with ... In other word I got syntax problem with the month pattern ... >>against the articles and help on regex, I still can't find the mistake I ... >> Public Function regtest(ByVal StringIn As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How do I shorten or split this function
    ...    (scan regex string) ... Instead of field-name you mean field-type. ... it doesn't test the string to see if it's of the suitable form for the ... corresponding field of the pattern. ...
    (comp.lang.lisp)