End of string

2 snippets in Regular Expressions

RXRegular Expressions

$ End of String

RX · Basic Patterns
syntax
pattern$
example
JS:  /\.json$/.test('config.json')   // true
JS:  /\.json$/.test('config.json.bak')  // false
Py:  bool(re.search(r'\.json$', 'config.json'))  # True
output
true, false, True

Note Matches position at end of string. With the m flag, $ matches the end of each line. In Python, re.match only checks the start -- use re.search with $ to check the end.

$ End Anchor

RX · Anchors & Boundaries
syntax
pattern$
example
JS:  /\.py$/.test('script.py')       // true
JS:  /\.py$/.test('script.py.bak')   // false
Py:  bool(re.search(r'\.py$', 'main.py'))  # True
output
true, false, True

Note Without the m flag, $ matches the very end of the string (or before a trailing newline in Python). With m, it matches the end of each line.