Language-Specific Syntax
Python
import re
# Match
match = re . search ( r ' \d+ ' , 'Phone: 123-456' )
if match :
print ( match . group ()) # "123"
# Find all
numbers = re . findall ( r ' \d+ ' , 'Phone: 123-456-7890' )
print ( numbers ) # ['123', '456', '7890']
# Replace
text = re . sub ( r ' \d+ ' , 'X' , 'Phone: 123' )
print ( text ) # "Phone: X"
# Split
parts = re . split ( r ' [-/] ' , '2024-01-15' )
print ( parts ) # ['2024', '01', '15']
# Compile for reuse
pattern = re . compile ( r ' \d+ ' )
result = pattern . findall ( '123 and 456' )
JavaScript
// Match
const match = '123-456' . match ( / \d+ / );
console . log ( match [ 0 ]); // "123"
// Find all
const numbers = '123-456-7890' . match ( / \d+ / g );
console . log ( numbers ); // ['123', '456', '7890']
// Test
const isValid = / ^\d{3}-\d{4}$ / . test ( '123-4567' );
console . log ( isValid ); // true
// Replace
const text = 'Phone: 123' . replace ( / \d+ / , 'X' );
console . log ( text ); // "Phone: X"
// Split
const parts = '2024-01-15' . split ( / [ -/ ] / );
console . log ( parts ); // ['2024', '01', '15']
SQL (Basic)
-- LIKE operator (limited regex)
SELECT * FROM users WHERE email LIKE '%@gmail.com' ;
-- REGEXP (MySQL)
SELECT * FROM users WHERE email REGEXP '^[a-z]+@[a-z]+\\.com$' ;
-- SIMILAR TO (PostgreSQL)
SELECT * FROM users WHERE email SIMILAR TO '[a-z]+@[a-z]+\\.com' ;