2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -v "c.*" dog can cat diz
2016-04-08 10:18:58 +08:00
dog
diz
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -q -r -v "c.*" dog can cat diz
2016-04-08 10:18:58 +08:00
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -v "c*" dog can cat diz
2016-04-08 10:18:58 +08:00
dog
diz
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -q -v "c*" dog can cat diz
2016-04-08 10:18:58 +08:00
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -v "d*" dog dan dat diz
2016-04-08 10:18:58 +08:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -q -v "d*" dog dan dat diz
2016-04-08 10:18:58 +08:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -v x y
2016-04-08 10:18:58 +08:00
y
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -v x x
2016-04-08 10:18:58 +08:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -q -r -v x y
2016-04-08 10:18:58 +08:00
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -q -r -v x x
2016-04-08 10:18:58 +08:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string length "hello, world"
2015-10-09 11:27:18 +08:00
12
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string length -q ""
zero length
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string sub --length 2 abcde
2015-10-09 11:27:18 +08:00
ab
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string sub -s 2 -l 2 abcde
2015-10-09 11:27:18 +08:00
bc
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string sub --start=-2 abcde
2015-10-09 11:27:18 +08:00
de
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string split . example.com
2015-10-09 11:27:18 +08:00
example
com
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string split -r -m1 / /usr/local/bin/fish
2015-10-09 11:27:18 +08:00
/usr/local/bin
fish
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string split "" abc
2015-10-09 11:27:18 +08:00
a
b
c
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# seq 3 | string join ...
2015-10-09 11:27:18 +08:00
1...2...3
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string trim " abc "
2015-10-09 11:27:18 +08:00
abc
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string trim --right --chars=yz xyzzy zany
2015-10-09 11:27:18 +08:00
x
zan
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# echo \x07 | string escape
2015-10-09 11:27:18 +08:00
\cg
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=script 'a b#c"\'d'
a\ b\#c\"\'d
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=url 'a b#c"\'d'
a%20b%23c%22%27d
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=url \na\nb%c~d\n
%0Aa%0Ab%25c~d%0A
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=var 'a b#c"\'d'
2017-06-22 20:47:54 -07:00
a_20_b_23_c_22_27_d
2017-06-20 21:55:16 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=script a\nghi_
a_0A_ghi__
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=var 'abc'
abc
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=var '_a_b_c_'
__a__b__c__
2017-08-04 12:51:48 -07:00
####################
2017-06-20 21:55:16 -07:00
# string escape --style=var -- -
_2D_
2018-11-07 12:37:47 +01:00
####################
# string escape with multibyte chars
a%C3%B6b
%E4%B8%AD
aöb
中
a_C3_B6_b
_E4_B8_AD_
aöb
中
2018-11-14 23:30:11 -06:00
####################
# string escape for literal pcre2 searching
\.ext
bonjour, amigo
\^this is a literal string
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# set x (string unescape (echo \x07 | string escape))
success
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=script (string escape --style=script 'a b#c"\'d')
a b#c"'d
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=url (string escape --style=url 'a b#c"\'d')
a b#c"'d
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=url (string escape --style=url \na\nb%c~d\n)
a
b%c~d
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=var (string escape --style=var 'a b#c"\'d')
a b#c"'d
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=var (string escape --style=var a\nghi_)
a
ghi_
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=var (string escape --style=var 'abc')
abc
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=var (string escape --style=var '_a_b_c_')
_a_b_c_
2017-08-04 12:51:48 -07:00
####################
2017-06-22 20:47:54 -07:00
# string unescape --style=var (string escape --style=var -- -)
-
2017-08-04 12:51:48 -07:00
####################
2018-03-31 16:48:57 -07:00
# string match "*" a
2015-10-09 11:27:18 +08:00
a
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match "a*b" axxb
2015-10-09 11:27:18 +08:00
axxb
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2018-03-31 16:48:57 -07:00
# string match -i "a**B" Axxb
2015-10-09 11:27:18 +08:00
Axxb
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2018-03-31 16:48:57 -07:00
# echo "ok?" | string match "*?"
2015-10-09 11:27:18 +08:00
ok?
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r "cat|dog|fish" "nice dog"
2015-10-09 11:27:18 +08:00
dog
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r "(\d\d?):(\d\d):(\d\d)" 2:34:56
2015-10-09 11:27:18 +08:00
2:34:56
2
34
56
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r "^(\w{2,4})\g1\$" papa mud murmur
2015-10-09 11:27:18 +08:00
papa
pa
murmur
mur
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -a -n at ratatat
2015-10-09 11:27:18 +08:00
2 2
4 2
6 2
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -i "0x[0-9a-f]{1,8}" "int magic = 0xBadC0de;"
2015-10-09 11:27:18 +08:00
0xBadC0de
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace is was "blue is my favorite"
2015-10-09 11:27:18 +08:00
blue was my favorite
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace 3rd last 1st 2nd 3rd
2015-10-09 11:27:18 +08:00
1st
2nd
last
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace -a " " _ "spaces to underscores"
2015-10-09 11:27:18 +08:00
spaces_to_underscores
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace -r -a "[^\d.]+" " " "0 one two 3.14 four 5x"
2015-10-09 11:27:18 +08:00
0 3.14 5
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
2015-10-09 11:27:18 +08:00
right left $
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace -r "\s*newline\s*" "\n" "put a newline here"
2015-10-09 11:27:18 +08:00
put a
here
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string replace -r -a "(\w)" "\$1\$1" ab
2016-02-21 14:59:03 -07:00
aabb
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-27 21:53:39 -07:00
# string replace --filter x X abc axc x def jkx
aXc
X
jkX
2017-08-04 12:51:48 -07:00
####################
2017-04-27 21:53:39 -07:00
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
Xbc
X
dXf
jkX
2017-08-04 12:51:48 -07:00
####################
# string match -r "[" "a[sd"
####################
# string invalidarg
####################
2017-04-24 21:05:51 -07:00
# string length
missing argument returns 1
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r -v "[dcantg].*" dog can cat diz
2016-04-08 10:18:58 +08:00
no regexp invert match
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2018-03-31 16:48:57 -07:00
# string match -v "*" dog can cat diz
2016-04-08 10:18:58 +08:00
no glob invert match
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -rvn a bbb
2016-05-31 23:14:03 +02:00
1 3
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n 2 "foo"
2017-03-07 15:39:21 +01:00
foofoo
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat --count 2 "foo"
2017-03-07 15:39:21 +01:00
foofoo
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# echo foo | string repeat -n 2
2017-03-07 15:39:21 +01:00
foofoo
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n2 -q "foo"
2017-03-07 15:39:21 +01:00
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n2 --quiet "foo"
2017-03-07 15:39:21 +01:00
exit 0
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n0 "foo"
2017-03-07 15:39:21 +01:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n0
2017-03-07 15:39:21 +01:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -m0
2017-03-07 15:39:21 +01:00
exit 1
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n1 -N "there is "
2017-03-07 15:39:21 +01:00
there is no newline
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n1 --no-newline "there is "
2017-03-07 15:39:21 +01:00
there is no newline
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n10 -m4 "foo"
2017-03-07 15:39:21 +01:00
foof
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n10 --max 5 "foo"
2017-03-07 15:39:21 +01:00
foofo
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n3 -m20 "foo"
2017-03-07 15:39:21 +01:00
foofoofoo
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -m4 "foo"
2017-03-07 15:39:21 +01:00
foof
2017-04-24 21:05:51 -07:00
2017-08-04 12:51:48 -07:00
####################
# string repeat -n-1 "foo"
####################
# string repeat -m-1 "foo"
####################
# string repeat -n notanumber "foo"
####################
# string repeat -m notanumber "foo"
####################
# echo "stdin" | string repeat -n1 "and arg"
####################
# string repeat -n
####################
# string repeat -l fakearg 2>&1
####################
2017-04-24 21:05:51 -07:00
# string repeat ""
string repeat empty string failed
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string repeat -n3 ""
string repeat empty string failed
2017-08-04 12:51:48 -07:00
####################
2017-05-01 22:19:58 -07:00
# string match -e x abc dxf xyz jkx x z
2017-04-24 21:05:51 -07:00
dxf
xyz
jkx
x
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match x abc dxf xyz jkx x z
x
2017-08-04 12:51:48 -07:00
####################
2017-05-01 22:19:58 -07:00
# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
2017-04-24 21:05:51 -07:00
abxc
bye
aaabyz
kaabxz
abbxy
caabxyxz
2018-09-16 13:03:15 +02:00
####################
# string match --entire "" -- banana
banana
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abx
by
aaaby
aabx
bxy
aabxyx
2017-08-04 12:51:48 -07:00
####################
2017-05-01 22:19:58 -07:00
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
2017-04-24 21:05:51 -07:00
abxc
x
bye
y
aaabyz
y
kaabxz
x
abbxy
xy
caabxyxz
xyx
2017-08-04 12:51:48 -07:00
####################
2017-04-24 21:05:51 -07:00
# string match -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
abx
x
by
y
aaaby
y
aabx
x
bxy
xy
aabxyx
xyx
2018-05-11 16:47:29 +02:00
####################
# Check NUL
a\x00b
a\x00c
a
\x00
d
a\x00b
a\x00g
a\x00g
2018-05-29 21:11:50 -07:00
####################
# string split0
1
3
4
3
2
1
2018-06-24 14:03:13 -07:00
####################
# string join0
3
2
2
2018-05-29 21:11:50 -07:00
####################
# string split0 in functions
4