Jump to content

Recommended Posts

A quick and dirty regex like

 

/<base\s*href=[\"\'](.*?)[\"\']>/is

 

will match the contents of href so you can replace it. "  .*  " is a greedy expression that basically means select everything possible. "  ?  " defines as few as possible (so it will match only up to the first quote is finds, need this otherwise it wil match up to the last quote which could be 1000 lines down the script such as many strings of "> exist usually)

 

Get yourself a copy of expresso, it did me wonders learning regex with it.

its for windows, you could run it under wine, its not as if you need it constantly. If you dont like wine you can probably find a mac regex builder, but i tried loads of builders for windows and i found expresso to be the best one. Personally preference i guess.

 

What do you mean by wildcard ? The * just means match any, so it will match href "" as well as href="really long string" . You could have used ".+?" and that would have meant "one or more" but if the href was ever empty, it wouldnt match anything. I guess it depends on what your actually trying to accomplish.

 

If by "find out what wildcard matched" you mean return the contents of href, then preg_match would do that. Not sure if theres a return matches in preg_replace, you'd have to check the php docs, its something ive never required to do so im not sure if theres a flag in the function for this or not

 

Hopefully that makes some sort of sense

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.