Regular Expressions: Character Classes in Sets
Welcome to the Character Classes in Sets lesson!
This lesson is shown as static text below. However, it's designed to be used interactively. Click the button below to start!
Suppose that we're writing a regex to process Lisp code. Unlike most languages, Lisp allows the "-" character in identifiers. We can use a character set including everything in
\was well as-.>
/^[\w-]+$/.test('a_function');Result:
true
>
/^[\w-]+$/.test('a-function');Result:
true
>
/^[\w-]+$/.test('(describe-number)');Result:
false