preg_match Characer Limit

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

preg_match Characer Limit

Post by shiznatix »

I have a very simple regex to grab a form field value after grabbing the page via curl. Here is my regex:

Code: Select all

preg_match('#id="__VIEWSTATE" value="(.*?)"#', $content, $matches);
and here is my field that I want the value from:

Code: Select all

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/1123ASdlotsandlotsandlotsofgarbage=" />
Now the value there is a made up one because the real one is 107076 long on average (seriously). Now this value can have everything from / A-Z 0-9 = + ... whatever they want so that is why I am using the (.*?) to just grab anything there. My regex seams to do just fine if I replace the super long value with just something short so I am starting to think that there is some sort of character limit set to what can be returned there. Is this true and if not, why would my regex not be working? If you want me to post a real whole value="" part then no problem, just is so long I didn't want to make it such a spammy post.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: preg_match Characer Limit

Post by prometheuzz »

shiznatix wrote:I have a very simple regex to grab a form field value after grabbing the page via curl. Here is my regex:

Code: Select all

preg_match('#id="__VIEWSTATE" value="(.*?)"#', $content, $matches);
and here is my field that I want the value from:

Code: Select all

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/1123ASdlotsandlotsandlotsofgarbage=" />
Now the value there is a made up one because the real one is 107076 long on average (seriously). Now this value can have everything from / A-Z 0-9 = + ... whatever they want so that is why I am using the (.*?) to just grab anything there. My regex seams to do just fine if I replace the super long value with just something short so I am starting to think that there is some sort of character limit set to what can be returned there. Is this true and if not, why would my regex not be working? If you want me to post a real whole value="" part then no problem, just is so long I didn't want to make it such a spammy post.
I am not aware of a limitation. Note that the DOT by default does not match new line characters, perhaps there are new line characters in your long value? Try to replace "(.*?)" with "([^"]*)".
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Re: preg_match Characer Limit

Post by shiznatix »

ah that was it, thanks hommie.
User avatar
prometheuzz
Forum Regular
Posts: 779
Joined: Fri Apr 04, 2008 5:51 am

Re: preg_match Characer Limit

Post by prometheuzz »

shiznatix wrote:ah that was it, thanks hommie.
Good to hear it!
Post Reply