Jump to content

Regular Expressions


Doreen22

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...