How do I use a regex in a shell script?

To complement the existing helpful answers: Using Bash’s own regex-matching operator, =~, is a faster alternative in this case, given that you’re only matching a single value already stored in a variable: set — ’12-34-5678′ # set $1 to sample value kREGEX_DATE=’^[0-9]{2}[-/][0-9]{2}[-/][0-9]{4}$’ # note use of [0-9] to avoid \d [[ $1 =~ $kREGEX_DATE ]] …

Read more

Regex: I want this AND that AND that… in any order

You can use (?=…) positive lookahead; it asserts that a given pattern can be matched. You’d anchor at the beginning of the string, and one by one, in any order, look for a match of each of your patterns. It’ll look something like this: ^(?=.*one)(?=.*two)(?=.*three).*$ This will match a string that contains “one”, “two”, “three”, …

Read more

Guide on how to use regex in Nginx location block section?

Nginx location: Nginx location block section have a search order, a modifier, an implicit match type and an implicit switch to whether stop the search on match or not. the following array describe it for regex. # ——————————————————————————————————————————————– # Search-Order Modifier Description Match-Type Stops-search-on-match # ——————————————————————————————————————————————– # 1st = The URI must match the specified …

Read more