tags:

views:

37

answers:

2

hi ,

i have the following regex which is working fine in JAVA code

[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?

but same is not working in the Java script

can any one please tell me the solution for this

thanks Sunny Mate

A: 

Regular Expression is slightly different in each programming language, please reference the manual/document.

itea
+1  A: 

I'd put the last hyphen from those sets as the first character:

Before:
[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]
After:
[-A-Za-z0-9!#$%&'*+/=?^_`{|}~]

The hyphen will allow a range of characters. It will be treated as hyphen if it is the first character of the set. Else, it could mean "from '~' until ']'"

But still, it's hard to answer precisely without a precise question.

EDIT: I've tested this expression on a simple JavaScript RegEx tester, and I discovered it is meant to match e-mail addresses. It worked for me after I replaced the double-backslashes \\ by single ones \.

In JavaScript, the following two should work the same:

var re = /a\.c/;  
var re = new RegExp("a\\.c");  

But the second one requires double back-slashes because it is enclosed in a string, which requires escaping. If all else fails, check Mozilla Developer Center.

But, again, it's impossible to give a precise answer without a precise question. What's more, when you try to improve your question, it's more likely that you will find your bug.

Denilson Sá