All stacks / Intents / Find substring Also written as locate substring
syntax Copy
/hello/ or r'hello' example Copy
JS: 'say hello world' .match(/hello/)
Py: re.search(r'hello' , 'say hello world' )output
Matches "hello" at index 4Note Characters that are not special match themselves exactly. Regex is case-sensitive by default -- use the i flag for case-insensitive matching.
syntax Copy
POSITION(substring IN string )
STRPOS(string , substring) example Copy
SELECT
email,
POSITION('@' IN email) AS at_position,
SUBSTRING(email FROM POSITION('@' IN email) + 1 ) AS domain
FROM users;output
-- email | at_position | domain
-- [email protected] | 6 | example.comNote Returns the 1-based position of the first occurrence. Returns 0 if not found (not -1 like most programming languages). MySQL uses LOCATE(substring, string) which has the arguments in reverse order.
Related tasks