-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregextr
More file actions
61 lines (53 loc) · 1.32 KB
/
regextr
File metadata and controls
61 lines (53 loc) · 1.32 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh
# usage: regextr [exp]*
#
# eg:
# capt=(
# /capt=)
# etc.
#
# see your ~/.regextr for the complete syntax, or the code just below
#
# it can be used yet to compose expressions:
#
# echo lol | pcregrep "`./regextr capt captname text /captname l repeated /capt`"
#
if [ "X$0" = "X" ]; then
echo "usage: regextr [exp]*"
exit
fi
if [ ! -e ~/.regextr ]; then
# creating default syntax file..
echo "exp=/" >>~/.regextr
echo "/exp=/" >>~/.regextr
echo "boundstart=^" >>~/.regextr
echo "boundend=$" >>~/.regextr
echo "capt=(" >>~/.regextr
echo "/capt=)" >>~/.regextr
echo "captor=|" >>~/.regextr
echo "captname=?<" >>~/.regextr
echo "/captname=>" >>~/.regextr
echo "range=[" >>~/.regextr
echo "notrange=[^" >>~/.regextr
echo "/range=]" >>~/.regextr
echo "digit=\d" >>~/.regextr
echo "string=." >>~/.regextr
echo "word=\w" >>~/.regextr
echo "space=\s" >>~/.regextr
echo "notspace=\S" >>~/.regextr
echo "repeated=+" >>~/.regextr
echo "maybenot=?" >>~/.regextr
echo "quant={" >>~/.regextr
echo "quantsep=-" >>~/.regextr
echo "/quant=}" >>~/.regextr
fi
res=""
for exp in $@; do
test=`pcregrep ^$exp\= ~/.regextr | cut -d = -s -f 2`
if [ "X$test" = "X" ]; then
res=$res$exp
else
res=$res`pcregrep ^$exp\= ~/.regextr | cut -d = -s -f 2`
fi
done
echo $res