Help with Regex

dickey

New Member
Messages
128
Reaction score
0
Points
0
hi

I have this regular expression in php using preg_replace...
PHP:
preg_match("/\"\w+\"\.z\(\)/", $string, $matches);

anyway to keep it short it matches...

"This is a string".z()

and

"Another string".z()

but it unfortunately matches...

"GET: "http://this.url.com/".z()

when I want it to only match "http://this.url.com/".z();

I am new to creating my own regex and want to resort to
doing
\"[a-zA-Z0-9\D]*\"\.z\(\)

or is there a better way...

My objective is to create a regex that matches a string enclosed within double quotes followed that is passed to a function z() in javascript. The source string is also pre-processed to replace any escaped quotes inside the string.
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
How about:

PHP:
function getData(){
if($_GET['somevar'] == $yourRegEx){
//do something
} 
else{
//do something else
}
}
getData();

Or did I completely misinterpret what you are asking? Lol. It's 1:00 am. So, it's completely possible.
 

garrettroyce

Community Support
Community Support
Messages
5,611
Reaction score
249
Points
63
i think you want:

"/"http[.*]/.z()/""

match any strings that start with "http with 0 or more characters to .z()"

it is frowned upon to use .*, but I think in this case it is the simplest way to do this. If you know the URL is only going to be http://example.com or http://mysite.com and not http://forum.othersite.com/someting/query.php?action=do&data=23513214;save you can probably use [a-zA-Z0-9_/.//]+ which should match one or more alphanumeric, underscore, forward slash, or period characters.

I'm new to regex, so I can't guarantee this will work, but it looks right to me :p
 
Top