Ask a Question related to Perl / CGI, Design and Development.

  1. #1

    Default regex problem

    Hi there,

    I have a regex problem.

    Basicly I do not want to match:

    /dir/test/contact.html

    But I do want to match:
    /test/contact.html

    I tryed this one:
    ^[!dir]/(.*)/contact(.*).html$

    but it does not work and I tryed thousands of other ways plus read
    tutorials.

    Can anybody please help?

    Thanx in advance


    Merlin Guest

  2. Similar Questions and Discussions

    1. Regex - Problem
      Hello! I have this RegEx: /(+:\/\/+)/i Now, I want to exlude on the end of a String the formats .gif / .jpg / ..png / .exe / .zip / .rar ...
    2. [PHP] regex problem
      So, what you want is to pretty much use this regex /^(.*)(+)\/(+)$/ when matched on this URI, the backreferences will contain \\1 partner/...
    3. [PHP] regex problem
      * Thus wrote Merlin (news.groups@web.de): I'm not sure what you expect since this *is* a php mailing list. Mod rewrite is a powerful tool and...
    4. [PHP] regex problem
      So ^+/* or ^!(partner/) Merlin wrote:
    5. [PHP] regex problem
      That's if($string == 'test/contact.html') of course... :) it could be if($string == "test/contact.html")
  3. #2

    Default Re: regex problem

    > ^\/test\/contact.html$

    does not work. I am sorry, I just found that

    it has to be:
    test/contact.html

    and not
    dir/test/contact.html

    there is no leading slash.

    Do you have any other suggestion?

    --
    <IFRAME
    SRC="http://saratoga.globosapiens/associates/report_member.php?u=3&color=EEE
    EEE" scrolling=no frameborder=0 TITLE="My travel articles" width="330"
    height="155" ALLOWTRANSPARENCY="true"><a href="http://www.globosapiens.net"
    title="Worldwide Travel Community"a>Travel Community<a/> </IFRAME>

    "Kae Verens" <kverens@contactjuggling.org> schrieb im Newsbeitrag
    news:20030815110908.35628.qmail@pb1.pair.com...
    > Merlin wrote:
    > > Hi there,
    > >
    > > I have a regex problem.
    > >
    > > Basicly I do not want to match:
    > >
    > > /dir/test/contact.html
    > >
    > > But I do want to match:
    > > /test/contact.html
    > >
    > > I tryed this one:
    > > ^[!dir]/(.*)/contact(.*).html$
    > >
    > > but it does not work and I tryed thousands of other ways plus read
    > > tutorials.
    > >
    > > Can anybody please help?
    >
    > ^\/test\/contact.html$
    >
    > Kae
    >

    Merlin Guest

  4. #3

    Default Re: regex problem

    Merlin wrote:
    > Hi there,
    >
    > I have a regex problem.
    >
    > Basicly I do not want to match:
    >
    > /dir/test/contact.html
    >
    > But I do want to match:
    > /test/contact.html
    >
    > I tryed this one:
    > ^[!dir]/(.*)/contact(.*).html$
    >
    > but it does not work and I tryed thousands of other ways plus read
    > tutorials.
    >
    > Can anybody please help?
    ^\/test\/contact.html$

    Kae

    Kae Verens Guest

  5. #4

    Default Re: regex problem

    Merlin wrote:
    >>^\/test\/contact.html$
    >
    >
    > does not work. I am sorry, I just found that
    >
    > it has to be:
    > test/contact.html
    >
    > and not
    > dir/test/contact.html
    >
    > there is no leading slash.
    >
    > Do you have any other suggestion?
    >
    *sigh*

    ^test\/contact.html$

    Kae

    Kae Verens Guest

  6. #5

    Default Re: regex problem

    ufff.. sorry guys, but I have to explain that better. I appreciate your
    help, maybe I did not give enough info.

    I am trying to redirect with apache modrewrite. To do this you have to use
    regex (not if functions:-)

    My problem is, that there are member accounts which look like that:

    membername/contact.html

    and there are partner accounts which look like this:

    partner/name/contact.html

    The goal is to redirect only if it is a member account. If I put a
    (.*)/contact.html it also matches the partner/
    I tryed putting a root / infront, but there is not / root for the url from
    apaches point of view.

    So I would need a regex which will match the member account, but if the
    first word is "partner" it should
    not terminate.

    This seems to be a tough one!

    Thanx for any help,

    Merlin

    "Kae Verens" <kverens@contactjuggling.org> schrieb im Newsbeitrag
    news:20030815122950.99785.qmail@pb1.pair.com...
    > Merlin wrote:
    > >>^\/test\/contact.html$
    > >
    > >
    > > does not work. I am sorry, I just found that
    > >
    > > it has to be:
    > > test/contact.html
    > >
    > > and not
    > > dir/test/contact.html
    > >
    > > there is no leading slash.
    > >
    > > Do you have any other suggestion?
    > >
    >
    > *sigh*
    >
    > ^test\/contact.html$
    >
    > Kae
    >

    Merlin Guest

  7. #6

    Default Re: regex problem

    Merlin wrote:
    > ufff.. sorry guys, but I have to explain that better. I appreciate your
    > help, maybe I did not give enough info.
    >
    > I am trying to redirect with apache modrewrite. To do this you have to use
    > regex (not if functions:-)
    >
    > My problem is, that there are member accounts which look like that:
    >
    > membername/contact.html
    >
    > and there are partner accounts which look like this:
    >
    > partner/name/contact.html
    >
    > The goal is to redirect only if it is a member account. If I put a
    > (.*)/contact.html it also matches the partner/
    > I tryed putting a root / infront, but there is not / root for the url from
    > apaches point of view.
    >
    > So I would need a regex which will match the member account, but if the
    > first word is "partner" it should
    > not terminate.
    >
    > This seems to be a tough one!
    >
    ah - maybe a chain of rewrites would do?

    send all matches of /^partner\/(.*)\/contact.html$/ to partner\/\1\/blah
    send all matches of /^(.*)\/contact.html$/ to NEWLOCATION
    send all matches of /^partner\/(.*)\/blah$/ to partner\/\1\/contact.html

    Kae

    Kae Verens Guest

  8. #7

    Default Re: regex problem

    Good idea,

    but does not work either - surprisingly! -

    There should be a clean way with regex for this task.


    Andy regex expert in here?

    Merlin



    "Kae Verens" <kverens@contactjuggling.org> schrieb im Newsbeitrag
    news:20030815133157.45726.qmail@pb1.pair.com...
    > Merlin wrote:
    > > ufff.. sorry guys, but I have to explain that better. I appreciate your
    > > help, maybe I did not give enough info.
    > >
    > > I am trying to redirect with apache modrewrite. To do this you have to
    use
    > > regex (not if functions:-)
    > >
    > > My problem is, that there are member accounts which look like that:
    > >
    > > membername/contact.html
    > >
    > > and there are partner accounts which look like this:
    > >
    > > partner/name/contact.html
    > >
    > > The goal is to redirect only if it is a member account. If I put a
    > > (.*)/contact.html it also matches the partner/
    > > I tryed putting a root / infront, but there is not / root for the url
    from
    > > apaches point of view.
    > >
    > > So I would need a regex which will match the member account, but if the
    > > first word is "partner" it should
    > > not terminate.
    > >
    > > This seems to be a tough one!
    > >
    >
    > ah - maybe a chain of rewrites would do?
    >
    > send all matches of /^partner\/(.*)\/contact.html$/ to partner\/\1\/blah
    > send all matches of /^(.*)\/contact.html$/ to NEWLOCATION
    > send all matches of /^partner\/(.*)\/blah$/ to partner\/\1\/contact.html
    >
    > Kae
    >

    Merlin Guest

  9. #8

    Default Regex problem

    I have a directory of files that I want to move to another directory.
    (eg. ALLY20030111W.eps
    TEST W20030122
    HELP WANTED20030901WW.eps
    GIRL WATCH BIRD 20030101
    etc..)

    I want to be able to parse the filename and replace the date portion
    with any date (eg $1="ALLY" $2="20030111" $3="W" $4=".eps")
    Then I want to make $2="20030925" and if $3 is empty then I assign ".eps"
    to $3 or if $4 is empty then assign ".eps"


    How do I do this?

    #!/usr/bin/perl
    # move_file.plx
    use warnings;
    use strict;

    $source = "/path/to/source/";
    $destination = "/path/to/destination/";
    $query = "([A-Za-z]+)(\s*?)([0-9]*)(\s*?)([A-Za-z]*)([eps])"
    opendir DH, $source or die "Couldn't open the current directory:
    $source"; while ($_ = readdir(DH)) {
    next if $_ eq "." or $_ eq "..";

    if (/$query/) {
    print "Copying $_ ...\n";
    rename $source$_, $destination$_;
    print "file copied successfully.\n";
    }
    }

    What's wrong with my code. Am I overlooking something?
    Gareth Segree Guest

  10. #9

    Default regex problem

    Notice I have to use the lines twice:

    "$line =~ s/###\s*?###/###empty###/g;
    $line =~ s/###\s*?###/###empty###/g;"

    in order to get the desired result. I've been playing
    for a long time but can't get it w/one regex expression. I wondered
    if I can put one regex into a loop(?) I think it has to do w/greedy
    vs. non-greedy. The code's is rough sorry - please find the output
    below too hjope you'll see what I'm trying and that repetive regex's
    are not a good solution - does anyone know the trick?

    Thanx,
    Lee





    #!/usr/bin/perl -wT
    use strict;
    use CGI qw(:standard);
    use CGI::Carp qw(fatalsToBrowser);

    print header, start_html('Tag Conversion'), h1('Tag Conversion');
    my $infile = param("in_file");
    my $count;
    if ($infile) {

    chomp($infile);
    print p("Input file: $infile");
    open (INFILE, "<$infile") || die "can't open '$infile': $!";
    my $line = <INFILE>;
    while ($line =~ /###/g)
    { $count++ }
    print p("There are $count fields in a record");
    print p("$line");
    $line =~ s/^\d+//;
    print p("$line");
    # my $repl = '###empty###';
    $line =~ s/###\s*?###/###empty###/g;
    $line =~ s/###\s*?###/###empty###/g;
    print p("$line");
    }
    elsif (param()) { # for sake of our discussion this block is not called

    my $infile = param("in_file");
    chomp($infile);

    print p("Input file: $infile");

    open (INFILE, "<$infile") || die "can't open '$infile': $!";

    while (<INFILE>) {
    chomp;
    s/^\d+//;
    my @rec_array = split( /###/, $_);
    print p($_);
    print p("@rec_array\n");
    }
    }
    else { # what user sees 1st
    print start_form();
    print p("What's your input file?: ", textfield("in_file"));
    print p(submit("Create Tagged File"));
    print end_form();
    }
    print end_html;


    -----OUTPUT--------

    There are 14 fields in a record

    1###o31025883###3C on-line ###New York NY The Association###Hardcopy###
    ### ###F1A###ACM SIGCCC###Computer Science/Information
    Technology###1078-2192###Quarterly### ### ###Goddard

    ###o31025883###3C on-line ###New York NY The Association###Hardcopy###
    ### ###F1A###ACM SIGCCC###Computer Science/Information
    Technology###1078-2192###Quarterly### ### ###Goddard

    ###o31025883###3C on-line ###New York NY The
    Association###Hardcopy###empty###empty###F1A###ACM SIGCCC###Computer
    Science/Information
    Technology###1078-2192###Quarterly###empty###empty###Goddard
    leegold Guest

  11. #10

    Default Regex problem

    I have the following regex: Salary&amp;lt;/h3>([[rint:]]+) The html Im
    trying to parse is:<h3>Salary</h3>?12,500 - ?14,500 pa</div> Here is my code
    to get the salary: <cfset
    MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3]
    ..xmlAttributes.re)#, cfhttp.FileContent,1,True)>
    <cfset thisSalary =
    mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])> Problem: The
    element at position 2 cannot be found. The error occurred in
    C:\CFusionMX\wwwroot\Project\1.cfm: line 33 Called from
    C:\CFusionMX\wwwroot\Project\1.cfm: line 21 Called from
    C:\CFusionMX\wwwroot\Project\1.cfm: line 1 31 : 32
    : <cfset
    MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3]
    ..xmlAttributes.re)#, cfhttp.FileContent,1,True)> 33 : <cfset thisSalary =
    mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])> Any ideas?,
    thanks

    samb1 Guest

  12. #11

    Default Regex Problem

    I have the following regex: Salary&amp;lt;/h3>([[rint:]]+) The html Im
    trying to parse is:<h3>Salary</h3>?12,500 - ?14,500 pa</div> Here is my code
    to get the salary: <cfset
    MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3]
    ..xmlAttributes.re)#, cfhttp.FileContent,1,True)>
    <cfset thisSalary =
    mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])> Problem: The
    element at position 2 cannot be found. The error occurred in
    C:\CFusionMX\wwwroot\Project\1.cfm: line 33 Called from
    C:\CFusionMX\wwwroot\Project\1.cfm: line 21 Called from
    C:\CFusionMX\wwwroot\Project\1.cfm: line 1 31 : 32
    : <cfset
    MatchSalary=REFindNoCase(#Trim(xmlObj.xmlRoot.site[1].detailpageparsers.parse[3]
    ..xmlAttributes.re)#, cfhttp.FileContent,1,True)> 33 : <cfset thisSalary =
    mid(cfhttp.FileContent,MatchSalary.pos[2],MatchSalary.len[2])> Any ideas?,
    thanks

    samb1 Guest

  13. #12

    Default RegEx problem

    I am trying to do a regular expression in Flex 3 actionscript:

    private function parseImageUrl(fromHtml:XMLList):String
    {

    var pattern:RegExp = /"image\/jpeg" src="(.+?)" /;
    var results:Array = pattern.exec(fromHtml);
    var imageURL:String = results[1]; // backreference 1 from
    pattern

    return imageURL;
    }

    This is the string that I am passing in:

    <content type="image/jpeg"
    src="http://lh6.ggpht.com/bryan/SBkgbpMm7dI/AAAAAAAAACo/PbmSgITG5iU/P4290026.JPG
    " xmlns="http://www.w3.org/2005/Atom"
    xmlnspenSearch="http://a9.com/-/spec/opensearchrss/1.0/"
    xmlns:exif="http://schemas.google.com/photos/exif/2007"
    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:georss="http://www.georss.org/georss"
    xmlnshoto="http://www.pheed.com/pheed/"
    xmlns:media="http://search.yahoo.com/mrss/"
    xmlns:batch="http://schemas.google.com/gdata/batch"
    xmlns:gphoto="http://schemas.google.com/photos/2007"/>

    I have tested the regular expression here
    [url]http://www.regular-expressions.info/javascriptexample.html[/url] and it says it is
    valid. So what do I seem to be doing wrong?

    TIA,

    Bryan


    bh5k Guest

  14. #13

    Default Re: RegEx problem

    The following code seems to work, and I did not alter your regex.

    output:
    [url]http://lh6.ggpht.com/bryan/SBkgbpMm7dI/AAAAAAAAACo/PbmSgITG5iU/P4290026.JPG[/url]



    <?xml version="1.0"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    [Bindable]
    private var str:String = '<content type="image/jpeg"
    src="http://lh6.ggpht.com/bryan/SBkgbpMm7dI/AAAAAAAAACo/PbmSgITG5iU/P4290026.JPG
    " xmlns="http://www.w3.org/2005/Atom"
    xmlnspenSearch="http://a9.com/-/spec/opensearchrss/1.0/"
    xmlns:exif="http://schemas.google.com/photos/exif/2007"
    xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
    xmlns:gml="http://www.opengis.net/gml"
    xmlns:georss="http://www.georss.org/georss"
    xmlnshoto="http://www.pheed.com/pheed/"
    xmlns:media="http://search.yahoo.com/mrss/"
    xmlns:batch="http://schemas.google.com/gdata/batch"
    xmlns:gphoto="http://schemas.google.com/photos/2007"/>';
    private function parseImageUrl(fromHtml:String):String {
    var pattern:RegExp = /"image\/jpeg" src="(.+?)" /;
    var results:Array = pattern.exec(fromHtml);
    var imageURL:String = results[1];
    return imageURL;
    }
    ]]>
    </mx:Script>
    <mx:Text text="{parseImageUrl(str)}"/>
    </mx:Application>

    Greg Lafrance Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139