Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-03-2003, 03:20 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 06-03-2003, 04:39 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Off to play some more
Reply With Quote
  #3  
Old 06-03-2003, 04:42 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dammit, you should have waited longer so I could come to the rescue with my regexp genius!

Remember to have the trailing /, too
Reply With Quote
  #4  
Old 06-03-2003, 05:18 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It's not working yet. Still time for you to be my knight in shining armor.

Arg! I HATE regular expressions!
Reply With Quote
  #5  
Old 06-03-2003, 05:23 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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);
but, either it's not finding the pattern, or it's not splitting it properly.

Amy
Reply With Quote
  #6  
Old 06-03-2003, 05:44 PM
gerlando gerlando is offline
 
Join Date: Apr 2002
Posts: 17
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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]);
Reply With Quote
  #7  
Old 06-03-2003, 05:53 PM
amykhar's Avatar
amykhar amykhar is offline
 
Join Date: Oct 2001
Location: PA
Posts: 4,438
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bless you for finding the error That's what comes from having bad eyes and a tutorial with fine print
Reply With Quote
  #8  
Old 06-03-2003, 06:02 PM
filburt1 filburt1 is offline
 
Join Date: Feb 2002
Location: Maryland, US
Posts: 6,144
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hint: anything you need returned in preg_match or preg_match_all should be in parens; for example:
PHP Code:
preg_match("/([A-Za-z0-9]*)stuff([0-9]*)/"$somestring$match);
echo 
"<pre>";
print_r($match); 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:35 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04674 seconds
  • Memory Usage 2,234KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete