-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathregexp_ex
More file actions
executable file
·36 lines (25 loc) · 941 Bytes
/
regexp_ex
File metadata and controls
executable file
·36 lines (25 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#
# Illustrates use of the regular expression API.
readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
. ${DIR}/../gobash
function main() {
local regexp
regexp=$(regexp_compile ".* not [zc]omplex") || \
return $EC
$regexp match_string " not zomplex" || \
{ echo "Expecting a match."; return $EC; }
$regexp match_string "something not complex" || \
{ echo "Expecting a match."; return $EC; }
local str
str=$($regexp find_string "a not zomplex text but still a match")
assert_eq "a not zomplex" "${str}" "String does not match."
regexp=$(regexp_compile "a (.*) b (.*) c") || \
return $EC
local lst
lst=$($regexp find_string_submatch "a abc b x c") || \
return $EC
assert_eq "abc" "$($lst get 1)"
assert_eq "x" "$($lst get 2)"
}
main