Starts with

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

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()).

RXRegular Expressions

^ 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).

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.