Page 1 of 1

Looking to REGEX a javascript doc.write

Posted: Sun Dec 24, 2006 6:51 pm
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";

Posted: Sun Dec 24, 2006 7:53 pm
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.

Re: Looking to REGEX a javascript doc.write

Posted: Sun Dec 24, 2006 9:06 pm
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]

Posted: Sun Dec 24, 2006 9:23 pm
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})(\)\))$";

Posted: Sun Dec 24, 2006 9:53 pm
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";
}