From 6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:38:56 +0200 Subject: Adding upstream version 5.2.15. Signed-off-by: Daniel Baumann --- tests/cond-regexp1.sub | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 tests/cond-regexp1.sub (limited to 'tests/cond-regexp1.sub') diff --git a/tests/cond-regexp1.sub b/tests/cond-regexp1.sub new file mode 100644 index 0000000..1ba9197 --- /dev/null +++ b/tests/cond-regexp1.sub @@ -0,0 +1,69 @@ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +VAR='[[:alpha:]]' + +[[ $VAR =~ '[[:alpha:]]' ]] && echo match 1 + +[[ a =~ '[[:alpha:]]' ]] || echo match 2 + +[[ a =~ [[:alpha:]] ]] && echo match 3 + +[[ a =~ $VAR ]] && echo match 4 + +[[ a =~ "$VAR" ]] || echo match 5 + +line=aab +[[ $line =~ [[:space:]]*(a)?b ]] && echo match 6 + +V="alphabet" +[[ $V == alphabet ]] && echo yes 1 +[[ $V == "alphabet" ]] && echo yes 2 +[[ $V == 'alphabet' ]] && echo yes 3 +[[ $V =~ alphabet ]] && echo yes 4 +[[ $V =~ "alphabet" ]] && echo yes 5 +[[ $V =~ 'alphabet' ]] && echo yes 6 + +DOG="Dog name - 01 - Wiggles" +REPAT='([[:alpha:][:blank:]]*)- ([[:digit:]]*) - (.*)$' +if [[ $DOG =~ ([[:alpha:][:blank:]]*)-\ ([[:digit:]]*)\ -\ (.*)$ ]] +then + echo Dog ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]} +fi +if [[ $DOG =~ $REPAT ]] +then + echo Dog ${BASH_REMATCH[2]} is ${BASH_REMATCH[3]} +fi + +[[ $REPAT =~ "$REPAT" ]] && echo rematch 1 + +v="one two buckle my shoe" +[[ ${v} =~ "one two" ]] && echo matches 7 + +[[ ${v} =~ (one two) ]] && echo matches 8 + +[[ ${v} =~ one\ two ]] && echo matches 9 + +unset pattern string +pattern="xxx.yyy" +string=xxxAyyy + +[[ $string =~ $pattern ]] && echo unquoted matches +[[ $string =~ "$pattern" ]] && echo quoted matches + +# problems in pre-patched bash-4.2 +[[ "helloworld" =~ llo ]] && echo match control-a 1 +[[ "helloworld" =~ world ]] && echo match control-a 2 +[[ "helloworld" =~ world$ ]] && echo match control-a 3 +[[ "helloworld" =~  ]] && echo match control-a 4 +[[ "helloworld" =~ oworld$ ]] && echo match control-a 5 -- cgit v1.2.3