Ask a Question related to Perl / CGI, Design and Development.
-
Merlin #1
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
-
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 ... -
[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/... -
[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... -
[PHP] regex problem
So ^+/* or ^!(partner/) Merlin wrote: -
[PHP] regex problem
That's if($string == 'test/contact.html') of course... :) it could be if($string == "test/contact.html") -
Merlin #2
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
-
Kae Verens #3
Re: regex problem
Merlin wrote:
^\/test\/contact.html$> 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?
Kae
Kae Verens Guest
-
Kae Verens #4
Re: regex problem
Merlin wrote:
*sigh*>>>^\/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?
>
^test\/contact.html$
Kae
Kae Verens Guest
-
Merlin #5
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
-
Kae Verens #6
Re: regex problem
Merlin wrote:
ah - maybe a chain of rewrites would do?> 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!
>
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
-
Merlin #7
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...use> 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 tofrom> > 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>> > 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
-
Gareth Segree #8
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
-
leegold #9
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
-
samb1 #10
Regex problem
I have the following regex: Salary&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
-
samb1 #11
Regex Problem
I have the following regex: Salary&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
-
bh5k #12
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"
xmlns
penSearch="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"
xmlns
hoto="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
-
Greg Lafrance #13
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"
xmlns
penSearch="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"
xmlns
hoto="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



Reply With Quote

