Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do I break up a regular expression in JavaScript

  String.prototype.is_email = function() {
      return this.match(/[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum)\b/);
  };

I'm trying to get all my javascript files to lint under closure linter ( http://code.google.com/closure/utilities/docs/linter_howto.html ); how do I break up a Regular Expression using the /regex/ syntax.

Line 24, E:0110: Line too long (200 characters). Found 1 errors, including 0 new errors, in 1 files (0 files OK).

like image 238
MathGladiator Avatar asked May 27 '26 00:05

MathGladiator


1 Answers

You can use the RegExp(pattern, modifiers) and pass the pattern as a string. The string can be built up in small parts using concatenation.

like image 139
Mark Byers Avatar answered May 28 '26 14:05

Mark Byers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!