0

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

2
  • 1
    Could you post you current javascript code explaining the expected outcome and the actual outcome? Commented Oct 28, 2010 at 9:29
  • please use a code block and escape the regex the right way so that it gets shown proper Commented Oct 28, 2010 at 9:29

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.