Looking to REGEX a javascript doc.write

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

Moderator: General Moderators

Post Reply
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Looking to REGEX a javascript doc.write

Post by jyhm »

Hello REGEX masters :wink:

As the title states I am trying to REGEX a javascript statement:

Code: Select all

document.write(formatTime('%I:%M%p', 1167096600))
Everything stays the same exept the 10digit numb. I have something like this but it doesn't work:

Code: Select all

$js_date="^(document\.write\(formatTime\(\'\%I\:\%M\%p\',)\s([0-9]{10})(\)\))$";
I'm also curious as to why some regular expressions are wrapped in double and single quots with an i stuck in there like this below. I have not found references on it.

Code: Select all

$search="'&(nbsp|#160);'i";
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

Ok, I'm sorry to waste your time. I'm in the process of reading the CRASH course tutotial posted in this forum. I will post results if I fix the problem.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Looking to REGEX a javascript doc.write

Post by John Cartwright »

jyhm wrote:Hello REGEX masters :wink:
Hi. ;)

Code: Select all

$js_date="^(document\.write\(formatTime\(\'\%I\:\%M\%p\',)\s([0-9]{10})(\)\))$";
Make sure you are only escaping characters that need to be escaped. You can also use the /d character instead of a number range.
I'm also curious as to why some regular expressions are wrapped in double and single quots with an i stuck in there like this below. I have not found references on it.
You can use any characters as delimeters. The more obvious ones are #, $, etc.
[/quote]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I'm not where I can test ATM, but it appears to e a syntax problem:

$js_date="^(document\.write\(formatTime\(\'\%I\:\%M\%p\',)\s([0-9]{10})(\)\))$";
User avatar
jyhm
Forum Contributor
Posts: 228
Joined: Tue Dec 19, 2006 10:08 pm
Location: Connecticut, USA
Contact:

Post by jyhm »

Thank you for you're input,

After reading this forums tutorial, I guess I have to learn the perl REGEX syntax while using pregmatch and preg_replace. Oh well, more stuff to learn! :wink:

this code works!

Code: Select all

"/document\.write\(formatTime\('%I:%M%p', \d{10}\)\)/"

Code: Select all

$js_strg="document.write(formatTime('%I:%M%p', 1167096600))"

if (preg_match("/document\.write\(formatTime\('%I:%M%p', \d{10}\)\)/", $js_strg)) {
    echo "this string is, ";
	echo $js_strg;
} else {
    echo "comprende nota senior";
}
Post Reply