Which Regex is superior?

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

Moderator: General Moderators

Post Reply
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Which Regex is superior?

Post by raghavan20 »

I have been using Regex in JavaScript in my applications. But I am wondering which one is the best and to be honest I dont know more about php Regex or Perl Regex.

1. Do you guys think that there are significant adv available in PHP over Javascript Regex?

2. Is Perl Regex superior to PHP Regex?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PCRE regex is typically superior. Perl is the origin of that variant. PHP has the preg_* which are PCRE. Javascript is similarly done... so the best... that depends on where you need it :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

JavaScript processing speed isn't too fast in comparison with PHP but that's not specific to regex and it depends upon the spec of the client machine. If there's no real reason to do it in JavaScript then dont because:

a).. They mightn't have JS on
b).. It may be slower
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Is there is anyway to find out the client machine has JavaScript enabled?
The reason I am using JavaScript cos if its executed at client machine, it wont overload the server.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's pretty easy to tell if JS is enabled:

Code: Select all

<script language="Javascript">document.write('<img src="jsEnabled.php" />');</scirpt><noscript><img src="realfile.png" /></noscript>
where jsEnabled.php would output realfile.png, but also record/set up/whatever that the user has JS enabled.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Is it possible to know it by value? like, I want to execute an condition and get the result as True or False to find whether Javascript is enabled.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it won't execute at all if javascript isn't enabled..
Post Reply