Ends with

4 snippets across 3 stacks — Regular Expressions, JavaScript, SQL

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.

JSJavaScript

String Searching

JS · Strings
syntax
str.includes(search, startIndex)
str.startsWith(search)
str.endsWith(search)
example
const msg = "Order #1234 shipped";
console.log(msg.includes("shipped"));   // true
console.log(msg.startsWith("Order"));   // true
console.log(msg.endsWith("shipped"));   // true
console.log(msg.indexOf("#"));          // 6

Note All search methods are case-sensitive. For case-insensitive checks, lowercase both sides first: str.toLowerCase().includes(term.toLowerCase()).

SQLSQL

LIKE Pattern Matching

SQL · Filtering
syntax
WHERE column LIKE 'pattern'
-- % = any number of characters
-- _ = exactly one character
example
SELECT first_name, email
FROM users
WHERE email LIKE '%@gmail.com';
output
-- All users with Gmail addresses

Note LIKE is case-sensitive in PostgreSQL but case-insensitive in MySQL (with default collation). PostgreSQL offers ILIKE for case-insensitive matching. A leading % prevents index usage.