从Javascript到PHP的正则表达式[关闭]

I Want to know if there is a tool for converting JavaScript Regex to PHP.

I got the following Regex in JAvascript

 var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

And

 pwbx2.match(/.[^!,+,§,\),\(,=,\-,\.,:,,,\w]/)

Now I wan't to match the given values to check also at the server side on this regex. How can i do it?

Cheers

Sven

You need to know that .[^!,+,§,\),\(,=,\-,\.,:,,,\w] is a monstrosity. In normal regex, this would be:

.[^-.,:+=!§()\w]

The [brackets] indicate a character class. They mean "match one character in this class," or, when the first charcter is ^ "match one character that is not in this class." So there is never any need to repeat a character in a character class. This one has eleven commas!

Your test could be expressed in this compact fashion:

$theregex = '~.[^-.,:+=!§()\w]~';
echo (preg_match($theregex, $yourstring)) ? "**It Matches!**" : "Nah... No match." ;

But that probably doesn't work the way you want anyway

The original regex begs the question: what where they thinking when they wrote this? Clearly whoever wrote this was regex-illiterate (and I don't mean to be gratuitously condescending... that's just a fact.) Therefore, it is quite likely that they had something quite different in mind when they wrote it. And if that's a case, it doesn't matter how well you translate it: it won't do the job it was intended for.

If you know what the regex is supposed to do, tell us, and we'll help you fix it.

you can use preg_match like this :

 $pattern="/.[^-.,:+=!§()\w]/";
 $string="your string to match";
 if( preg_match($pattern,$string) != 1){
    echo "nothing found";
 }else{
    echo "found";
 }