Jump to content

Recommended Posts

Having a problem. I'm crap at regex.

 

I'm using cURL which is returning me a string from a visited webpage. I'm trying scrape MemberIds:

 

The member ids look like so in the returned string (checked the source of the webpage too)

 

/Profile.jsp?MemberId=4394229250

 

The Id can be any length, as long as its a number.

 

Was trying this: but it was only returning the /Profile.jsp?MemberId= part and not the number.

 

$pattern = "/Profile\.jsp\?MemberId=(.*?)/";
preg_match_all($pattern,$string,$matches);

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/162307-solved-preg_match_all/
Share on other sites

You solved it? If not, try removing the dollar sign from your latest pattern - it matches at the end of the haystack, and that's not where the member IDs are, I guess (and only one match would be possible there). If you want to capture the IDs in an array in $matches[1], surround \d+ in parentheses.

 

~/Profile\.jsp\?MemberId=(\d+)~

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.