Execute Program

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 \w as well as -.

  • >
    /^[\w-]+$/.test('a_function');
    Result:
    truePass Icon
  • >
    /^[\w-]+$/.test('a-function');
    Result:
    truePass Icon
  • >
    /^[\w-]+$/.test('(describe-number)');
    Result:
    falsePass Icon