Click to See Complete Forum and Search --> : [RESOLVED] PHP preg_match_all -> JS match


Ultimater
05-16-2007, 06:12 PM
I've been trying to convert an entire PHP function to JavaScript which converts alphabetical characters to Hebrew characters. One of the regular expressions my PHP uses is:

<?php
preg_match_all('/[A-Z][a-z]*?|./U',$strin,$result);
?>

Although JavaScript doesn't come with a "U" modifier.
If I'm not mistaken is my PHP also the same as saying:

<?php
preg_match_all('/[A-Z][a-z]*|./',$strin,$result);
?>

One more question, is the above the same as:

<?php
preg_match_all('/[A-Z][a-z]*|[\s\S]/',$strin,$result);
?>

Answer me the PHP questions then I'll be able to solve the JavaScript one.

If you care to see what my JavaScript looks like so far:

<script type="text/javascript">
result=new String(strin).match(/[A-Z][a-z]*|[\s\S]/g);
</script>

I'm just not sure if it is an equivalent or if there are any small differences between the two.

Ultimater
05-16-2007, 06:19 PM
Oh wait... I found the error.

My PHP read:

$l=count($tttt);


And my JavaScript was using:

l=tttt.length;

which was ending up in "undefined" on null elements while PHP was passing it as 0.
I had to change it to:

l=(typeof tttt.length!='undefined')?tttt.length:0;