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.

Frequently asked questions

How does JavaScript handle starts with?
This task is covered in 3 stacks on this page: JavaScript, Regular Expressions, SQL. The "String Searching" snippet in JavaScript uses `str.includes(search, startIndex)`.
Which code does the JavaScript example use?
The "String Searching" snippet uses `str.includes(search, startIndex)`, from the Strings section of the JavaScript cheat sheet.
Which stacks cover "starts with" on this page?
JavaScript, Regular Expressions, SQL. Together they hold 3 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "String Searching": All search methods are case-sensitive. For case-insensitive checks, lowercase both sides first: str.toLowerCase().includes(term.toLowerCase()).