Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Javascript RegExp support POSIX expressions?

Tags:

javascript

I have a password <input> box in a <form> element my html body

When a user click on the submit button in the sign up form, I can get javascript to determine whether the string the user typed in the password box is a combination of alphabet and/ or numbers by using the following code

$("#password1").val().match(new RegExp(/[a-zA-Z1-9]{1,}/));

However when I tried using the expression below, it returns "null" which gives me the impression that POSIX expressions are not supported in javascript... or is it somewhere along the line I am missing something?

$("#password1").val().match(new RegExp(/[[:alnum:]]{1,}/));
like image 293
repzero Avatar asked Jul 07 '15 23:07

repzero


People also ask

What is Posix in regex?

POSIX bracket expressions are a special kind of character classes. POSIX bracket expressions match one character out of a set of characters, just like regular character classes. They use the same syntax with square brackets.

Does JavaScript support regex?

Using regular expressions in JavaScript. Regular expressions are used with the RegExp methods test() and exec() and with the String methods match() , replace() , search() , and split() . Executes a search for a match in a string. It returns an array of information or null on a mismatch.

What does RegExp do in JavaScript?

RegExp Object A regular expression is a pattern of characters. The pattern is used to do pattern-matching "search-and-replace" functions on text. In JavaScript, a RegExp Object is a pattern with Properties and Methods.

What does (? I do in regex?

E.g. (? i-sm) turns on case insensitivity, and turns off both single-line mode and multi-line mode.


2 Answers

Posix expressions such as :alnum: are not supported, though some other backslash-escaped character classes (like \w for word characters including alphanumeric characters and the underscore) are allowed.

like image 182
Jeff Bowman Avatar answered Oct 21 '22 18:10

Jeff Bowman


POSIX character classes are not supported, but you can find JavaScript equivalents to them here:

http://www.regular-expressions.info/posixbrackets.html

like image 33
royb Avatar answered Oct 21 '22 17:10

royb