| View previous topic :: View next topic |
| Author |
Message |
eiSi Halfop
Joined: 07 Mar 2002 Posts: 70
|
Posted: Tue Aug 16, 2005 6:56 am Post subject: another regexp problem |
|
|
hi there!
I started to concern myself with regexp now, and I already have a problem:
the string ($text):
| Code: | | <a href=/item.html?witem=647>Destiny</a> |
my code:
| Code: | | 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 |
|
| Back to top |
|
 |
avilon Halfop

Joined: 13 Jul 2004 Posts: 64 Location: Germany
|
Posted: Tue Aug 16, 2005 9:15 am Post subject: |
|
|
| Code: | | scan $text "<a href=/item.html?witem=%d>*</a>" digit |
647 is stored in $digit. |
|
| Back to top |
|
 |
eiSi Halfop
Joined: 07 Mar 2002 Posts: 70
|
Posted: Tue Aug 16, 2005 9:34 am Post subject: |
|
|
ah thanks a lot!
but I'm interested, what was wrong with my regexp? |
|
| Back to top |
|
 |
greenbear Owner
Joined: 24 Sep 2001 Posts: 733 Location: Norway
|
Posted: Tue Aug 16, 2005 9:51 am Post subject: |
|
|
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: | | 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: | | regexp {witem=(.*?)>} $text . digit |
|
|
| Back to top |
|
 |
eiSi Halfop
Joined: 07 Mar 2002 Posts: 70
|
Posted: Tue Aug 16, 2005 10:08 am Post subject: |
|
|
| ah alright, thanks for your help! |
|
| Back to top |
|
 |
|