Regex

They have: 568 posts

Joined: Nov 1999

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.

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).]

They have: 568 posts

Joined: Nov 1999

thats close, it prints the first letter but i need the whole word.

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.

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.

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.

They have: 568 posts

Joined: Nov 1999

It says

The province of Name(11:11) as of April 14, YR4.

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.

They have: 568 posts

Joined: Nov 1999

that works great, thanks a lot.

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.