Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Multisplit/UNIX-Shell/multisplit.sh
Normal file
29
Task/Multisplit/UNIX-Shell/multisplit.sh
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
multisplit() {
|
||||
local str=$1
|
||||
shift
|
||||
local regex=$( IFS='|'; echo "$*" )
|
||||
local sep
|
||||
while [[ $str =~ $regex ]]; do
|
||||
sep=${BASH_REMATCH[0]}
|
||||
words+=( "${str%%${sep}*}" )
|
||||
seps+=( "$sep" )
|
||||
str=${str#*$sep}
|
||||
done
|
||||
words+=( "$str" )
|
||||
}
|
||||
|
||||
words=() seps=()
|
||||
|
||||
original="a!===b=!=c"
|
||||
recreated=""
|
||||
|
||||
multisplit "$original" "==" "!=" "="
|
||||
|
||||
for ((i=0; i<${#words[@]}; i++)); do
|
||||
printf 'w:"%s"\ts:"%s"\n' "${words[i]}" "${seps[i]}"
|
||||
recreated+="${words[i]}${seps[i]}"
|
||||
done
|
||||
|
||||
if [[ $original == $recreated ]]; then
|
||||
echo "successfully able to recreate original string"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue