Jump to content

Regular Expressions


Doreen22
 Share

Recommended Posts

I have seen regular expressions declared a few different ways, in Javascript. Which is best?1) var regex = new RegExp(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/);2) var regex=/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/ ;3) same as 2, but without the semicolon at the end (my program chokes on that one, but I've seen it on several sites). I am using Javascript in XHTML code (not sure if that makes a difference). Thanks!Doreen

Link to comment
Share on other sites

XHTML won't make a difference.1 and 2 both create a regex object. I have the impression that most experienced developers use 2. The use of a semicolon at the end of a statement is optional, but most experienced developers do it.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...