regex starts with and ends with code example

Example 1: regex all starting with

#check if word starts with "test"

^test.*$

Example 2: regular expression starts and ends with same symbol

/^(a|e|i|o|u).*\1$/

Example 3: regex starts with

{ "Category" : /^ABC.*/ }

Example 4: regex start line

// Match from the start of the line
^
//example:
let str = "HELLO hello world"
let reg = /hello/g //g option: doesn't stop at first match
str.match(reg) // Array(2)["HELLO", "hello"]
reg = /^hello/g //match hello at the start of the string
str.match(reg) // Array(1)["HELLO"]

Example 5: regex ends with string

$ is used to match the end of the string. and can be used like

"string"$
like

xyz$
if you want to end with xzy

Tags:

Sql Example