The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
A challenge for regular expressions gurus
I need to figure out how to strip a certain style of number from urls. The challenge, I know the format of the number, but the actual number will be different every time. The second challenge? The number can appear in different places in the url.
I need to strip numbers that look like this: 102-5152600-7203338 from urls that look like this: http://www.amazon.com/exec/obidos/tg...125745-6132915 or this: http://www.amazon.com/exec/obidos/tg...utlet&n=548166 or whatever other crazy format Amazon decides to use. |
#2
|
||||
|
||||
I'm making progress. Turns out, I can lop off everything after the pattern of numbers that I am looking for. And, I believe the reg exp that I need to find looks like this:
Code:
/[0-9](3)-[0-9](7)-[0-9](7) |
#3
|
|||
|
|||
Dammit, you should have waited longer so I could come to the rescue with my regexp genius!
Remember to have the trailing /, too |
#4
|
||||
|
||||
It's not working yet. Still time for you to be my knight in shining armor.
Arg! I HATE regular expressions! |
#5
|
||||
|
||||
Here's the problem, I need to find the pattern, and then preserve everything BEFORE the pattern. I can discard the rest.
I figured this would work: Code:
list($url,$rest) = split("/[0-9](3)-[0-9](7)-[0-9](7)/",$string); Amy |
#6
|
|||
|
|||
I'm just learning Regex's myself, but I think you should try and simplify things and make sure its finding the pattern before you try doing anything else to it (like the split).
The error you have in your regex is the parens. they should be curly brakets i.e. [0-9]{3}-[0-9]{7}-[0-9]{7}, other then that it will work, I tested it in javascript since i don't have a php server available. Here's what I used for reference. var referrer="http://www.amazon.com/exec/obidos/tg/browse/-/548166/102-6125745-6132915"; regex=/[0-9]{3}-[0-9]{7}-[0-9]{7}/i; var ar = regex.exec(referrer); Response.write (ar[0]); |
#7
|
||||
|
||||
Bless you for finding the error That's what comes from having bad eyes and a tutorial with fine print
|
#8
|
|||
|
|||
Hint: anything you need returned in preg_match or preg_match_all should be in parens; for example:
PHP Code:
|
Thread Tools | |
Display Modes | |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|