1

How do I properly use RegExp?

var text = "here come dat boi o shit waddup";
var exmaple = /[a-zA-Z0-9 ]/; // allowes a-zA-Z0-9 and whitespaces but nothing else right?
example.test(test); // would return true right?

text = "%coconut$ยง=";
example.test(text); // would return false right?

//I know this is very basic - I started learnig all this about week ago

Are JS RegExp's the same as PHP RegExp's?
How do I define banned characters instead of defining allowed characters?
How do I make it so that the var text has to contain 3 (or more) numbers/letters?
How do I include / or ",'$ etc. in my pattern?

Aspire
  • 56
  • 6

1 Answers1

1
  1. No.

  2. Use ^ character (i.e. [^abc] will exclude a, b and c)

  3. Use [A-Za-z]{3} for letters and \d{3} for digits. If you want 3 or more, use \d{3,}

  4. Use escape character (\/, \', \", '\$')