2017-04-25 12:05:51 +08:00
|
|
|
# string match -r -v "c.*" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
dog
|
|
|
|
diz
|
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -q -r -v "c.*" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -v "c*" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
dog
|
|
|
|
diz
|
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -q -v "c*" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -v "d*" dog dan dat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -q -v "d*" dog dan dat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -r -v x y
|
2016-04-08 10:18:58 +08:00
|
|
|
y
|
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -r -v x x
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -q -r -v x y
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -q -r -v x x
|
2016-04-08 10:18:58 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string length "hello, world"
|
2015-10-09 11:27:18 +08:00
|
|
|
12
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string length -q ""
|
|
|
|
zero length
|
|
|
|
|
|
|
|
# string sub --length 2 abcde
|
2015-10-09 11:27:18 +08:00
|
|
|
ab
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string sub -s 2 -l 2 abcde
|
2015-10-09 11:27:18 +08:00
|
|
|
bc
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string sub --start=-2 abcde
|
2015-10-09 11:27:18 +08:00
|
|
|
de
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string split . example.com
|
2015-10-09 11:27:18 +08:00
|
|
|
example
|
|
|
|
com
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string split -r -m1 / /usr/local/bin/fish
|
2015-10-09 11:27:18 +08:00
|
|
|
/usr/local/bin
|
|
|
|
fish
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string split "" abc
|
2015-10-09 11:27:18 +08:00
|
|
|
a
|
|
|
|
b
|
|
|
|
c
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# seq 3 | string join ...
|
2015-10-09 11:27:18 +08:00
|
|
|
1...2...3
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string trim " abc "
|
2015-10-09 11:27:18 +08:00
|
|
|
abc
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string trim --right --chars=yz xyzzy zany
|
2015-10-09 11:27:18 +08:00
|
|
|
x
|
|
|
|
zan
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# echo \x07 | string escape
|
2015-10-09 11:27:18 +08:00
|
|
|
\cg
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match "?" a
|
2015-10-09 11:27:18 +08:00
|
|
|
a
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match "a*b" axxb
|
2015-10-09 11:27:18 +08:00
|
|
|
axxb
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -i "a??B" Axxb
|
2015-10-09 11:27:18 +08:00
|
|
|
Axxb
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# echo "ok?" | string match "*\?"
|
2015-10-09 11:27:18 +08:00
|
|
|
ok?
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -r "cat|dog|fish" "nice dog"
|
2015-10-09 11:27:18 +08:00
|
|
|
dog
|
2017-04-25 12:05:51 +08: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-25 12:05:51 +08: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-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -r -a -n at ratatat
|
2015-10-09 11:27:18 +08:00
|
|
|
2 2
|
|
|
|
4 2
|
|
|
|
6 2
|
2017-04-25 12:05:51 +08: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-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string replace is was "blue is my favorite"
|
2015-10-09 11:27:18 +08:00
|
|
|
blue was my favorite
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string replace 3rd last 1st 2nd 3rd
|
2015-10-09 11:27:18 +08:00
|
|
|
1st
|
|
|
|
2nd
|
|
|
|
last
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string replace -a " " _ "spaces to underscores"
|
2015-10-09 11:27:18 +08:00
|
|
|
spaces_to_underscores
|
2017-04-25 12:05:51 +08: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-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string replace -r "(\w+)\s+(\w+)" "\$2 \$1 \$\$" "left right"
|
2015-10-09 11:27:18 +08:00
|
|
|
right left $
|
2017-04-25 12:05:51 +08: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-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string replace -r -a "(\w)" "\$1\$1" ab
|
2016-02-22 05:59:03 +08:00
|
|
|
aabb
|
2017-04-25 12:05:51 +08:00
|
|
|
|
2017-04-28 12:53:39 +08:00
|
|
|
# string replace --filter x X abc axc x def jkx
|
|
|
|
aXc
|
|
|
|
X
|
|
|
|
jkX
|
|
|
|
|
|
|
|
# string replace --regex -f "\d" X 1bc axc 2 d3f jk4 xyz
|
|
|
|
Xbc
|
|
|
|
X
|
|
|
|
dXf
|
|
|
|
jkX
|
|
|
|
|
2017-04-25 12:05:51 +08:00
|
|
|
# string length
|
|
|
|
missing argument returns 1
|
|
|
|
|
|
|
|
# string match -r -v "[dcantg].*" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
no regexp invert match
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -v "???" dog can cat diz
|
2016-04-08 10:18:58 +08:00
|
|
|
no glob invert match
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string match -rvn a bbb
|
2016-06-01 05:14:03 +08:00
|
|
|
1 3
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n 2 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foofoo
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat --count 2 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foofoo
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# echo foo | string repeat -n 2
|
2017-03-07 22:39:21 +08:00
|
|
|
foofoo
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n2 -q "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n2 --quiet "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
exit 0
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n0 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n0
|
2017-03-07 22:39:21 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -m0
|
2017-03-07 22:39:21 +08:00
|
|
|
exit 1
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n1 -N "there is "
|
2017-03-07 22:39:21 +08:00
|
|
|
there is no newline
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n1 --no-newline "there is "
|
2017-03-07 22:39:21 +08:00
|
|
|
there is no newline
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n10 -m4 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foof
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n10 --max 5 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foofo
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -n3 -m20 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foofoofoo
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat -m4 "foo"
|
2017-03-07 22:39:21 +08:00
|
|
|
foof
|
2017-04-25 12:05:51 +08:00
|
|
|
|
|
|
|
# string repeat ""
|
|
|
|
string repeat empty string failed
|
|
|
|
|
|
|
|
# string repeat -n3 ""
|
|
|
|
string repeat empty string failed
|
|
|
|
|
2017-05-02 13:19:58 +08:00
|
|
|
# string match -e x abc dxf xyz jkx x z
|
2017-04-25 12:05:51 +08:00
|
|
|
dxf
|
|
|
|
xyz
|
|
|
|
jkx
|
|
|
|
x
|
|
|
|
|
|
|
|
# string match x abc dxf xyz jkx x z
|
|
|
|
x
|
|
|
|
|
2017-05-02 13:19:58 +08:00
|
|
|
# string match --entire -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
2017-04-25 12:05:51 +08:00
|
|
|
abxc
|
|
|
|
bye
|
|
|
|
aaabyz
|
|
|
|
kaabxz
|
|
|
|
abbxy
|
|
|
|
caabxyxz
|
|
|
|
|
|
|
|
# string match -r "a*b[xy]+" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
|
|
|
abx
|
|
|
|
by
|
|
|
|
aaaby
|
|
|
|
aabx
|
|
|
|
bxy
|
|
|
|
aabxyx
|
|
|
|
|
2017-05-02 13:19:58 +08:00
|
|
|
# string match --entire -r "a*b([xy]+)" abc abxc bye aaabyz kaabxz abbxy abcx caabxyxz
|
2017-04-25 12:05:51 +08:00
|
|
|
abxc
|
|
|
|
x
|
|
|
|
bye
|
|
|
|
y
|
|
|
|
aaabyz
|
|
|
|
y
|
|
|
|
kaabxz
|
|
|
|
x
|
|
|
|
abbxy
|
|
|
|
xy
|
|
|
|
caabxyxz
|
|
|
|
xyx
|
|
|
|
|
|
|
|
# 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
|