randomguy1234 Posted July 23, 2012 Share Posted July 23, 2012 I'm really clueless about regex. I've written a pattern: /<div class=\"search_result_item\" onclick=\"window.location='([^']+)/ My code is something like: randomcharacters <div class="search_result_item" onclick="window.location='/summoner/na/19997298'; return false;"> I need that "19997298" out of there, but I get: <div class="search_result_item" onclick="window.location='/summoner/na/19997298 Help me? I'm new to Regex Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/ Share on other sites More sharing options...
xyph Posted July 23, 2012 Share Posted July 23, 2012 Use var_dump($match) to see how the function is returning the results. Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/#findComment-1363715 Share on other sites More sharing options...
randomguy1234 Posted July 23, 2012 Author Share Posted July 23, 2012 It returns: array(2) { [0]=> string(79) " string(21) "/summoner/na/19997298" } Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/#findComment-1363720 Share on other sites More sharing options...
xyph Posted July 23, 2012 Share Posted July 23, 2012 Oh, silly me. Will the value before the number always be /summoner/na/, or is there a chance it won't be? Will there always be 3 forward-slashes before the number? Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/#findComment-1363776 Share on other sites More sharing options...
randomguy1234 Posted July 23, 2012 Author Share Posted July 23, 2012 Both true. Always /summoner/na/NUMBER and always only three slashes. Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/#findComment-1363789 Share on other sites More sharing options...
xyph Posted July 23, 2012 Share Posted July 23, 2012 So why not use something like $expr = "$<div class=\"search_result_item\" onclick=\"window.location='/summoner/na/([0-9]+)$"; Link to comment https://forums.phpfreaks.com/topic/266117-beginner-at-regex/#findComment-1363795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.