Regex
I have a simple regular expression that looks something like this
if($data=~ /one (.*) three (.*) five/) {
print "$1 and $1\n";
}
but it doesn't print anything for $1 and $2
please help.
I have a simple regular expression that looks something like this
if($data=~ /one (.*) three (.*) five/) {
print "$1 and $1\n";
}
but it doesn't print anything for $1 and $2
please help.
Rob Pengelly posted this at 18:46 — 3rd December 1999.
They have: 850 posts
Joined: Jul 1999
Instead of (.*)
try (.+?)
Also maybe use "m" before the first / so the regexp knows you are trying to match one "somthing" three "somthing" five, etc
if($data=~ m/one (.+?) three (.+?) five/)
{
print "$1 and $2\n";
}
Try that.
------------------
The longest recorded flight of a chicken is 13 seconds.
[This message has been edited by robp (edited 03 December 1999).]
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Orpheus posted this at 21:01 — 3rd December 1999.
They have: 568 posts
Joined: Nov 1999
thats close, it prints the first letter but i need the whole word.
Rob Pengelly posted this at 21:34 — 3rd December 1999.
They have: 850 posts
Joined: Jul 1999
Hmm, thats wierd that it only gets the first letter.
if
$data="one two three four";
than using
if($data=~ m/one(.+?)three(.+?)five/)
{
print "$1 and $2\n";
}
should print
"two and four"
------------------
The longest recorded flight of a chicken is 13 seconds.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Orpheus posted this at 22:43 — 3rd December 1999.
They have: 568 posts
Joined: Nov 1999
the exact thing i'm trying to match is
The province of XXX (XX:XX) as of April 17, YR4
it's a program for an online game i'm trying to make.
I need $1 to be XXX (XX:XX) and $2 to be April 17, YR4
maybe that will help a little bit.
Rob Pengelly posted this at 00:00 — 4th December 1999.
They have: 850 posts
Joined: Jul 1999
what does the $data contain?
$data="XXX (XX:XX)April 17, YR4";?
------------------
The longest recorded flight of a chicken is 13 seconds.
Orpheus posted this at 00:05 — 4th December 1999.
They have: 568 posts
Joined: Nov 1999
It says
The province of Name(11:11) as of April 14, YR4.
Rob Pengelly posted this at 00:52 — 4th December 1999.
They have: 850 posts
Joined: Jul 1999
ok, this will work
$data="The province of Name(11:11) as of April 14, YR4.";
while ($data =~ m/The province of (.+) as of (.+)./sogi)
{
print "$1 and $2";
}
------------------
The longest recorded flight of a chicken is 13 seconds.
http://www.thehungersite.com - http://www.therainforestsite.com
http://www.ratemymullet.com - Beauty is only mullet deep.
Orpheus posted this at 00:59 — 4th December 1999.
They have: 568 posts
Joined: Nov 1999
that works great, thanks a lot.
sumengen posted this at 14:04 — 5th December 1999.
They have: 15 posts
Joined: Jun 2000
Just a small correction:
while ($data =~ m/The province of (.+) as of (.+)\./sogi)
------------------
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.