Execute Program

Regular Expressions: Wildcard

Welcome to the Wildcard lesson!

This lesson is shown as static text below. However, it's designed to be used interactively. Click the button below to start!

  • Regexes like /a/ are literal: they specify exact characters to match. The real power in regexes is in the various operators. The most basic is ., the wildcard operator. It matches any character. But the character must be present; . won't match the empty string.

  • >
    /./.test('a');
    Result:
    truePass Icon
  • >
    /./.test('b');
    Result:
    truePass Icon
  • >
    /./.test('>');
    Result:
    truePass Icon
  • >
    /./.test('');
    Result:
    falsePass Icon
  • There's one important special case for /./: it doesn't match newlines!

  • >
    /./.test('\n');
    Result:
    falsePass Icon
  • Putting . next to another character means that they occur consecutively. For example, /a./ matches an "a" followed by any character. And /.a/ matches any character followed by an "a".

  • >
    /x.z/.test('xyz');
    Result:
    truePass Icon
  • >
    /x.z/.test('xaz');
    Result:
    truePass Icon
  • >
    /x.z/.test('xyyz');
    Result:
    falsePass Icon
  • >
    /x.z/.test('x_z');
    Result:
    truePass Icon
  • When there are multiple .s, they can match different characters.

  • >
    /x..z/.test('xaaz');
    Result:
    truePass Icon
  • >
    /x..z/.test('xaz');
    Result:
    falsePass Icon
  • >
    /x..z/.test('xabz');
    Result:
    truePass Icon