Anchor start

2 snippets in Regular Expressions

Also written as start anchor

RXRegular Expressions

^ Start of String

RX · Basic Patterns
syntax
^pattern
example
JS:  /^Error/.test('Error: file missing')   // true
JS:  /^Error/.test('An Error occurred')   // false
Py:  bool(re.match(r'^Error', 'Error: file missing'))  # True
output
true, false, True

Note Matches position at start of string. With the m (multiline) flag, ^ matches the start of each line instead. Do not confuse this with [^...] inside a character class, which means negation.

^ Start Anchor

RX · Anchors & Boundaries
syntax
^pattern
example
JS:  /^#!/.test('#!/bin/bash')    // true
JS:  /^#!/.test('echo #!/bin')   // false
Py:  bool(re.match(r'^#!', '#!/usr/bin/env python'))  # True
output
true, false, True

Note Without the m flag, ^ matches only the very beginning of the entire string. With the m flag, it matches the start of each line (after every newline character).