Regex Help

Discussion in 'Perl Misc' started by lmcosorio@hotmail.com, Aug 15, 2006.

  1. Guest

    Hi Everyone,

    I've been learning Perl for about 6 months. This is my first post to
    the group as it's also the first time i couldn't find an answer on this
    group or elsewhere.

    Here's my problem. I want to match a line from a file with the
    following conditions:

    1 - It starts with aaa?
    2 - Has random characthers following the "?"
    3 - ends with s=196

    1 & 2 are variables.

    Below is a sample script a wrote that shows (almost) what i need. I use
    the \Q modifier because of the "?" on the 1st variable.
    I can't seem to figure out how to match randoms characters between
    $var1 and $var2. To make things harder (at least for me) the randoms
    characters can contain special regex characters.

    use strict;
    use warnings;
    my $match1='aaa?';
    my $match2='s=196';
    my $var='aaa?s=196';

    if ($var =~ /\Q$match1$match2/)
    {
    print "It matched...";
    }


    where i have:
    if ($var =~ /\Q$match1$match2/)

    i need to have

    if ($var =~ /\Q$match1[match any random characters]$match2/)

    Any help apreciated.
    I hope my question is understandable and please forgive my english.

    Regards,

    Luis
    , Aug 15, 2006
    #1
    1. Advertising

  2. Dr.Ruud Guest

    schreef:

    > if ($var =~ /\Q$match1[match any random characters]$match2/)



    I think you are looking for:

    $var =~ /\A\Q${match1}\E.*\Q${match2}\E\z/)

    --
    Affijn, Ruud

    "Gewoon is een tijger."
    Dr.Ruud, Aug 15, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SmViQnVzaGVsbA==?=

    Is ASP Validator Regex Engine Same As VS2003 Find Regex Engine?

    =?Utf-8?B?SmViQnVzaGVsbA==?=, Oct 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    684
    =?Utf-8?B?SmViQnVzaGVsbA==?=
    Oct 22, 2005
  2. Rick Venter

    perl regex to java regex

    Rick Venter, Oct 29, 2003, in forum: Java
    Replies:
    5
    Views:
    1,599
    Ant...
    Nov 6, 2003
  3. Replies:
    2
    Views:
    585
  4. Xah Lee
    Replies:
    1
    Views:
    924
    Ilias Lazaridis
    Sep 22, 2006
  5. Replies:
    3
    Views:
    716
    Reedick, Andrew
    Jul 1, 2008
Loading...

Share This Page