This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

another regexp problem

Old posts that have not been replied to for several years.
Locked
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

another regexp problem

Post by eiSi »

hi there!

I started to concern myself with regexp now, and I already have a problem:

the string ($text):

Code: Select all

<a href=/item.html?witem=647>Destiny</a>
my code:

Code: Select all

regexp {\.html\?witem=([0-9]*?)\>} $text result
I know there's anything wrong with it, but I don't know what.

the match I get is: .html?witem=647>
but I want to get: 647

thanks for any help!

regards,
eiSi
User avatar
avilon
Halfop
Posts: 64
Joined: Tue Jul 13, 2004 6:58 am
Location: Germany

Post by avilon »

Code: Select all

scan $text "<a href=/item.html?witem=%d>*</a>" digit
647 is stored in $digit.
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

Post by eiSi »

ah thanks a lot!

but I'm interested, what was wrong with my regexp?
g
greenbear
Owner
Posts: 733
Joined: Mon Sep 24, 2001 8:00 pm
Location: Norway

Post by greenbear »

There's nothing wrong with your regexp, you just missed the 2nd var at the end.
Regexp writes the entire matching pattern to the first var.

So this should work:

Code: Select all

regexp {\.html\?witem=([0-9]*?)\>} $text garbage result
You dont have to make it this complex, though. You could probably have gotten away with doing something like this:

Code: Select all

regexp {witem=(.*?)>} $text . digit
e
eiSi
Halfop
Posts: 70
Joined: Thu Mar 07, 2002 8:00 pm

Post by eiSi »

ah alright, thanks for your help!
Locked