Jump to content

Matching a string in quotes with a | in the middle.


Lukeidiot

Recommended Posts

I can match this fine:

type="submit" value="Login">

 

using this regex...

 

preg_match_all('/name="action" value="(.*)">/', $source, $matches);

 

However, I cannot match this:

name="op3sfdkkfd" value="c90484908cc5d1b99c55f0191bba1932|1344564474">

 

with this:

preg_match_all('/name="op3sfdkkfd" value="(.*)">/', $source, $matches);

 

I believe the problem is that it has a "|" in the middle and is messing it up.

 

I am trying to match this part:

c90484908cc5d1b99c55f0191bba1932|1344564474

 

Any idea guys? Thanks in advance.

 

I am using the script to login to my domains registration site, then change the DNS A record to a mirror site in case the server ever goes down.

Link to comment
Share on other sites

I believe the problem is that it has a "|" in the middle and is messing it up.

Nope. Pipes only matter when they're in the regex itself - pipes in the source text are fine.

 

Are you sure the name isn't a random string?

 

Yeah that's what I thought too, however this is not the case.

 

Here is the actual source I am using:

https://internetbs.net

Link to comment
Share on other sites

As per your regex, the problem is in your quantifier (i.e the '*').

 

'/name="action" value="(.*)">/'

 

That '.*' is telling the regex engine to find every possible character, up to the LAST instace of '">'. So it is capturing the start of the value to the very last closing tag on the page (with a parameter) in it. You need to either make the quantifier lazy by using '.*?' (which is not too efficient) or better yet, change your expression to this:

 

'/name="action" value="([^"]*)">/'

 

So now, after it finds the matching text at the beginning (up to the opening quote for the value) it will capture all non-quote mark characters - up to the next quote mark. So the regex will be matching/returning the content of the value parameter as you wanted.

Link to comment
Share on other sites

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.