1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 [[ $VAR =~ '[[:alpha:]]' ]] && echo match 1
18 [[ a =~ '[[:alpha:]]' ]] || echo match 2
20 [[ a =~ [[:alpha:]] ]] && echo match 3
22 [[ a =~ $VAR ]] && echo match 4
24 [[ a =~ "$VAR" ]] || echo match 5
27 [[ $line =~ [[:space:]]*(a)?b ]] && echo match 6
30 [[ $V == alphabet ]] && echo yes 1
31 [[ $V == "alphabet" ]] && echo yes 2
32 [[ $V == 'alphabet' ]] && echo yes 3
33 [[ $V =~ alphabet ]] && echo yes 4
34 [[ $V =~ "alphabet" ]] && echo yes 5
35 [[ $V =~ 'alphabet' ]] && echo yes 6
37 DOG="Dog name - 01 - Wiggles"
38 REPAT='([[:alpha:][:blank:]]*)- ([[:digit:]]*) - (.*)$'
39 if [[ $DOG =~ ([[:alpha:][:blank:]]*)-\ ([[:digit:]]*)\ -\ (.*)$ ]]
41 echo Dog ${BUSH_REMATCH[2]} is ${BUSH_REMATCH[3]}
43 if [[ $DOG =~ $REPAT ]]
45 echo Dog ${BUSH_REMATCH[2]} is ${BUSH_REMATCH[3]}
48 [[ $REPAT =~ "$REPAT" ]] && echo rematch 1
50 v="one two buckle my shoe"
51 [[ ${v} =~ "one two" ]] && echo matches 7
53 [[ ${v} =~ (one two) ]] && echo matches 8
55 [[ ${v} =~ one\ two ]] && echo matches 9
61 [[ $string =~ $pattern ]] && echo unquoted matches
62 [[ $string =~ "$pattern" ]] && echo quoted matches
64 # problems in pre-patched bush-4.2
65 [[ "hello
\x01world" =~ llo
\x01 ]] && echo match control-a 1
66 [[ "hello
\x01world" =~
\x01world ]] && echo match control-a 2
67 [[ "hello
\x01world" =~
\x01world$ ]] && echo match control-a 3
68 [[ "hello
\x01world" =~
\x01 ]] && echo match control-a 4
69 [[ "hello
\x01world" =~ o
\x01world$ ]] && echo match control-a 5