Any questions involving matching text strings to patterns - the pattern is called a "regular expression."
Moderator: General Moderators
Mr Tech
Forum Contributor
Posts: 424 Joined: Tue Aug 10, 2004 3:08 am
Post
by Mr Tech » Wed Oct 17, 2007 1:26 am
I still cannot get my head around regex. So frustrating!
I need to replace something like this:
Code: Select all
<a target="_blank" href="page.html" class="link">
With this:
Code: Select all
<a target="_blank" href="#" class="link">
Any ideas?
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Wed Oct 17, 2007 1:34 am
If I understand what you're trying to do, a better solution might be to "return false" from your link's onclick() handler. Returning false keeps the click event from following the link.
Mr Tech
Forum Contributor
Posts: 424 Joined: Tue Aug 10, 2004 3:08 am
Post
by Mr Tech » Wed Oct 17, 2007 6:33 pm
That code worked! Thanks!
Also, thanks Kieran as that is a great idea
Mr Tech
Forum Contributor
Posts: 424 Joined: Tue Aug 10, 2004 3:08 am
Post
by Mr Tech » Thu Oct 18, 2007 2:35 am
Little old me again...
Normally you can use $1 to put whatever the value of the [^"] is but it isn't working in this case. Am I doing something wrong. Here's my code...
Code: Select all
$template = preg_replace('#src="[^"]+#im', "src=\"http://www.domain.com/$1", $template);
Kieran Huggins
DevNet Master
Posts: 3635 Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:
Post
by Kieran Huggins » Thu Oct 18, 2007 3:05 am
capturing parentheses are the round kind, the square ones are character classes