regex 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,106 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "REGEX" "1" "October 2011" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBregex\fR \- regular expression tool
8
+ .
9
+ .SH "DESCRIPTION"
10
+ Regex is a simple commmandline Regular Expression tool, that makes it easy to search documents for content matches\.
11
+ .
12
+ .P
13
+ Yea, I know what you are going to say\. "I can do that with ____" Fill in the blank with +grep+, +awk+, +sed+, +perl+, etc\. But honestly, none of these tools are as straight forward and capable as one might want\. What is needed is a simple command\-line tool that gives quick access to a Regular Expression engine\. No more, no less\.
14
+ .
15
+ .P
16
+ Now this could have written this in Perl\. No doubt, it would be just as good, if not better since Perl\'s Regualar Expression engine rocks (or so it is said)\. But Ruby\'s is pretty damn good too, and getting better (with 1\.9+)\. And since your humble author knows Ruby very well\.\.\.\. Well that\'s what you get\.
17
+ .
18
+ .SH "OPTIONS"
19
+ The \fBregex\fR command line has the following options\.
20
+ .
21
+ .SS "Search Options"
22
+ .
23
+ .IP "\(bu" 4
24
+ \fB\-s\fR, \fB\-\-search PATTERN\fR \- Search for this pattern\.
25
+ .
26
+ .IP "\(bu" 4
27
+ \fB\-t\fR, \fB\-\-template NAME\fR \- Use a built\-in regular expression (instead of \fB\-s\fR)\.
28
+ .
29
+ .IP "\(bu" 4
30
+ \fB\-i\fR, \fB\-\-insensitive\fR \- Case insensitive matching\.
31
+ .
32
+ .IP "\(bu" 4
33
+ \fB\-m\fR, \fB\-\-multiline\fR \- Multiline matching\.
34
+ .
35
+ .IP "\(bu" 4
36
+ \fB\-g\fR, \fB\-\-global\fR \- Global search\. By default regex only searches for the first match\. Use the global option to search for all matches\.
37
+ .
38
+ .IP "\(bu" 4
39
+ \fB\-e\fR, \'\-\-escape\' \- Make all patterns verbatim string matchers\.
40
+ .
41
+ .IP "\(bu" 4
42
+ \fB\-n\fR, \fB\-\-index INT\fR \- Return a specific match index\.
43
+ .
44
+ .IP "\(bu" 4
45
+ \fB\-R\fR, \fB\-\-recursive\fR \- Search though subdirectories recursively\.
46
+ .
47
+ .IP "\(bu" 4
48
+ \fB\-y\fR, \fB\-\-yaml\fR \- Output in YAML format\.
49
+ .
50
+ .IP "\(bu" 4
51
+ \fB\-j\fR, \fB\-\-json\fR \- Output in JSON format\.
52
+ .
53
+ .IP "\(bu" 4
54
+ \fB\-d\fR, \fB\-\-detail\fR \- Provide match details\.
55
+ .
56
+ .IP "" 0
57
+ .
58
+ .SS "Replace Options"
59
+ .
60
+ .IP "\(bu" 4
61
+ \fB\-r\fR, \fB\-\-replace TEXT\fR \- Replace matching pattern with the given text\.
62
+ .
63
+ .IP "\(bu" 4
64
+ \fB\-b\fR, \fB\-\-backup\fR \- Backup any files that are changed\.
65
+ .
66
+ .IP "" 0
67
+ .
68
+ .SS "Special Options"
69
+ .
70
+ .IP "\(bu" 4
71
+ \fB\-\-[no\-]ansi\fR \- Toggle ansi color\.
72
+ .
73
+ .IP "\(bu" 4
74
+ \fB\-\-debug\fR \- Run in debug mode\.
75
+ .
76
+ .IP "\(bu" 4
77
+ \fB\-h\fR, \fB\-\-help\fR \- Display this lovely help message\.
78
+ .
79
+ .IP "" 0
80
+ .
81
+ .SH "OUTPUT"
82
+ Regex has three output modes\. YAML, JSON and standard text\. The standard text output is unique in that it utilizes special ASCII characters to separate matches and regex groups\. ASCII 29, called the \fIrecord separator\fR, is used to separate repeat matches\. ASCII 30, called the \fIgroup separator\fR, is is used to separate regular expression groups\.
83
+ .
84
+ .SH "EXAMPLES"
85
+ The following example returns the content between the first \fB=begin \.\.\. =end\fR clause it comes across\.
86
+ .
87
+ .P
88
+ $ regex \'/=begin\.\fI?\en(\.\fR)\en=end/\' sample\.rb
89
+ .
90
+ .P
91
+ Instead of the first argument being the regular expresion, we can use the \fB\-s\fR option\. This exampe finds the first line starting with a Q\.
92
+ .
93
+ .P
94
+ $ regex \-s \' sample\.txt
95
+ .
96
+ .P
97
+ This example would replace all words starting with an X with an A in all \.txt files in the current directory\.
98
+ .
99
+ .P
100
+ $ regex \-g \-s \'\ebX\' \-r \'A\' *\.txt
101
+ .
102
+ .SH "COPYRIGHTS"
103
+ Copyright (c) 2009 Thomas Sawyer, Rubyworks
104
+ .
105
+ .P
106
+ Regex is distributable in accordance with the terms of the BSD\-2\-Clause license\.
@@ -0,0 +1,170 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv='content-type' value='text/html;charset=utf8'>
5
+ <meta name='generator' value='Ronn/v0.7.3 (http://github.com/rtomayko/ronn/tree/0.7.3)'>
6
+ <title>regex(1) - regular expression tool</title>
7
+ <style type='text/css' media='all'>
8
+ /* style: man */
9
+ body#manpage {margin:0}
10
+ .mp {max-width:100ex;padding:0 9ex 1ex 4ex}
11
+ .mp p,.mp pre,.mp ul,.mp ol,.mp dl {margin:0 0 20px 0}
12
+ .mp h2 {margin:10px 0 0 0}
13
+ .mp > p,.mp > pre,.mp > ul,.mp > ol,.mp > dl {margin-left:8ex}
14
+ .mp h3 {margin:0 0 0 4ex}
15
+ .mp dt {margin:0;clear:left}
16
+ .mp dt.flush {float:left;width:8ex}
17
+ .mp dd {margin:0 0 0 9ex}
18
+ .mp h1,.mp h2,.mp h3,.mp h4 {clear:left}
19
+ .mp pre {margin-bottom:20px}
20
+ .mp pre+h2,.mp pre+h3 {margin-top:22px}
21
+ .mp h2+pre,.mp h3+pre {margin-top:5px}
22
+ .mp img {display:block;margin:auto}
23
+ .mp h1.man-title {display:none}
24
+ .mp,.mp code,.mp pre,.mp tt,.mp kbd,.mp samp,.mp h3,.mp h4 {font-family:monospace;font-size:14px;line-height:1.42857142857143}
25
+ .mp h2 {font-size:16px;line-height:1.25}
26
+ .mp h1 {font-size:20px;line-height:2}
27
+ .mp {text-align:justify;background:#fff}
28
+ .mp,.mp code,.mp pre,.mp pre code,.mp tt,.mp kbd,.mp samp {color:#131211}
29
+ .mp h1,.mp h2,.mp h3,.mp h4 {color:#030201}
30
+ .mp u {text-decoration:underline}
31
+ .mp code,.mp strong,.mp b {font-weight:bold;color:#131211}
32
+ .mp em,.mp var {font-style:italic;color:#232221;text-decoration:none}
33
+ .mp a,.mp a:link,.mp a:hover,.mp a code,.mp a pre,.mp a tt,.mp a kbd,.mp a samp {color:#0000ff}
34
+ .mp b.man-ref {font-weight:normal;color:#434241}
35
+ .mp pre {padding:0 4ex}
36
+ .mp pre code {font-weight:normal;color:#434241}
37
+ .mp h2+pre,h3+pre {padding-left:0}
38
+ ol.man-decor,ol.man-decor li {margin:3px 0 10px 0;padding:0;float:left;width:33%;list-style-type:none;text-transform:uppercase;color:#999;letter-spacing:1px}
39
+ ol.man-decor {width:100%}
40
+ ol.man-decor li.tl {text-align:left}
41
+ ol.man-decor li.tc {text-align:center;letter-spacing:4px}
42
+ ol.man-decor li.tr {text-align:right;float:right}
43
+ </style>
44
+ </head>
45
+ <!--
46
+ The following styles are deprecated and will be removed at some point:
47
+ div#man, div#man ol.man, div#man ol.head, div#man ol.man.
48
+
49
+ The .man-page, .man-decor, .man-head, .man-foot, .man-title, and
50
+ .man-navigation should be used instead.
51
+ -->
52
+ <body id='manpage'>
53
+ <div class='mp' id='man'>
54
+
55
+ <div class='man-navigation' style='display:none'>
56
+ <a href="#NAME">NAME</a>
57
+ <a href="#DESCRIPTION">DESCRIPTION</a>
58
+ <a href="#OPTIONS">OPTIONS</a>
59
+ <a href="#OUTPUT">OUTPUT</a>
60
+ <a href="#EXAMPLES">EXAMPLES</a>
61
+ <a href="#COPYRIGHTS">COPYRIGHTS</a>
62
+ </div>
63
+
64
+ <ol class='man-decor man-head man head'>
65
+ <li class='tl'>regex(1)</li>
66
+ <li class='tc'></li>
67
+ <li class='tr'>regex(1)</li>
68
+ </ol>
69
+
70
+ <h2 id="NAME">NAME</h2>
71
+ <p class="man-name">
72
+ <code>regex</code> - <span class="man-whatis">regular expression tool</span>
73
+ </p>
74
+
75
+ <h2 id="DESCRIPTION">DESCRIPTION</h2>
76
+
77
+ <p>Regex is a simple commmandline Regular Expression tool, that makes it easy
78
+ to search documents for content matches.</p>
79
+
80
+ <p>Yea, I know what you are going to say. "I can do that with ____" Fill in the blank
81
+ with +grep+, +awk+, +sed+, +perl+, etc. But honestly, none of these tools are
82
+ as straight forward and capable as one might want. What is needed is a simple
83
+ command-line tool that gives quick access to a Regular Expression engine.
84
+ No more, no less.</p>
85
+
86
+ <p>Now this could have written this in Perl. No doubt, it would be just as good, if
87
+ not better since Perl's Regualar Expression engine rocks (or so it is said).
88
+ But Ruby's is pretty damn good too, and getting better (with 1.9+). And since
89
+ your humble author knows Ruby very well.... Well that's what you get.</p>
90
+
91
+ <h2 id="OPTIONS">OPTIONS</h2>
92
+
93
+ <p>The <code>regex</code> command line has the following options.</p>
94
+
95
+ <h3 id="Search-Options">Search Options</h3>
96
+
97
+ <ul>
98
+ <li><p><code>-s</code>, <code>--search PATTERN</code> - Search for this pattern.</p></li>
99
+ <li><p><code>-t</code>, <code>--template NAME</code> - Use a built-in regular expression (instead of <code>-s</code>).</p></li>
100
+ <li><p><code>-i</code>, <code>--insensitive</code> - Case insensitive matching.</p></li>
101
+ <li><p><code>-m</code>, <code>--multiline</code> - Multiline matching.</p></li>
102
+ <li><p><code>-g</code>, <code>--global</code> - Global search. By default regex only searches for the
103
+ first match. Use the global option to search for all matches.</p></li>
104
+ <li><p><code>-e</code>, '--escape' - Make all patterns verbatim string matchers.</p></li>
105
+ <li><p><code>-n</code>, <code>--index INT</code> - Return a specific match index.</p></li>
106
+ <li><p><code>-R</code>, <code>--recursive</code> - Search though subdirectories recursively.</p></li>
107
+ <li><p><code>-y</code>, <code>--yaml</code> - Output in YAML format.</p></li>
108
+ <li><p><code>-j</code>, <code>--json</code> - Output in JSON format.</p></li>
109
+ <li><p><code>-d</code>, <code>--detail</code> - Provide match details.</p></li>
110
+ </ul>
111
+
112
+
113
+ <h3 id="Replace-Options">Replace Options</h3>
114
+
115
+ <ul>
116
+ <li><p><code>-r</code>, <code>--replace TEXT</code> - Replace matching pattern with the given text.</p></li>
117
+ <li><p><code>-b</code>, <code>--backup</code> - Backup any files that are changed.</p></li>
118
+ </ul>
119
+
120
+
121
+ <h3 id="Special-Options">Special Options</h3>
122
+
123
+ <ul>
124
+ <li><p><code>--[no-]ansi</code> - Toggle ansi color.</p></li>
125
+ <li><p><code>--debug</code> - Run in debug mode.</p></li>
126
+ <li><p><code>-h</code>, <code>--help</code> - Display this lovely help message.</p></li>
127
+ </ul>
128
+
129
+
130
+ <h2 id="OUTPUT">OUTPUT</h2>
131
+
132
+ <p>Regex has three output modes. YAML, JSON and standard text. The standard
133
+ text output is unique in that it utilizes special ASCII characters
134
+ to separate matches and regex groups. ASCII 29, called the <em>record separator</em>,
135
+ is used to separate repeat matches. ASCII 30, called the <em>group separator</em>, is
136
+ is used to separate regular expression groups.</p>
137
+
138
+ <h2 id="EXAMPLES">EXAMPLES</h2>
139
+
140
+ <p>The following example returns the content between the first <code>=begin ... =end</code>
141
+ clause it comes across.</p>
142
+
143
+ <p> $ regex '/=begin.<em>?\n(.</em>)\n=end/' sample.rb</p>
144
+
145
+ <p>Instead of the first argument being the regular expresion, we can use the <code>-s</code>
146
+ option. This exampe finds the first line starting with a Q.</p>
147
+
148
+ <p> $ regex -s '<sup>Q'</sup> sample.txt</p>
149
+
150
+ <p>This example would replace all words starting with an X with an A in all .txt
151
+ files in the current directory.</p>
152
+
153
+ <p> $ regex -g -s '\bX' -r 'A' *.txt</p>
154
+
155
+ <h2 id="COPYRIGHTS">COPYRIGHTS</h2>
156
+
157
+ <p>Copyright (c) 2009 Thomas Sawyer, Rubyworks</p>
158
+
159
+ <p>Regex is distributable in accordance with the terms of the BSD-2-Clause license.</p>
160
+
161
+
162
+ <ol class='man-decor man-foot man foot'>
163
+ <li class='tl'></li>
164
+ <li class='tc'>October 2011</li>
165
+ <li class='tr'>regex(1)</li>
166
+ </ol>
167
+
168
+ </div>
169
+ </body>
170
+ </html>
@@ -0,0 +1,97 @@
1
+ regex(1) - regular expression tool
2
+ ==================================
3
+
4
+ ## DESCRIPTION
5
+
6
+ Regex is a simple commmandline Regular Expression tool, that makes it easy
7
+ to search documents for content matches.
8
+
9
+ Yea, I know what you are going to say. "I can do that with ____" Fill in the blank
10
+ with +grep+, +awk+, +sed+, +perl+, etc. But honestly, none of these tools are
11
+ as straight forward and capable as one might want. What is needed is a simple
12
+ command-line tool that gives quick access to a Regular Expression engine.
13
+ No more, no less.
14
+
15
+ Now this could have written this in Perl. No doubt, it would be just as good, if
16
+ not better since Perl's Regualar Expression engine rocks (or so it is said).
17
+ But Ruby's is pretty damn good too, and getting better (with 1.9+). And since
18
+ your humble author knows Ruby very well.... Well that's what you get.
19
+
20
+
21
+ ## OPTIONS
22
+
23
+ The `regex` command line has the following options.
24
+
25
+ ### Search Options
26
+
27
+ * `-s`, `--search PATTERN` - Search for this pattern.
28
+
29
+ * `-t`, `--template NAME` - Use a built-in regular expression (instead of `-s`).
30
+
31
+ * `-i`, `--insensitive` - Case insensitive matching.
32
+
33
+ * `-m`, `--multiline` - Multiline matching.
34
+
35
+ * `-g`, `--global` - Global search. By default regex only searches for the
36
+ first match. Use the global option to search for all matches.
37
+
38
+ * `-e`, '--escape' - Make all patterns verbatim string matchers.
39
+
40
+ * `-n`, `--index INT` - Return a specific match index.
41
+
42
+ * `-R`, `--recursive` - Search though subdirectories recursively.
43
+
44
+ * `-y`, `--yaml` - Output in YAML format.
45
+
46
+ * `-j`, `--json` - Output in JSON format.
47
+
48
+ * `-d`, `--detail` - Provide match details.
49
+
50
+ ### Replace Options
51
+
52
+ * `-r`, `--replace TEXT` - Replace matching pattern with the given text.
53
+
54
+ * `-b`, `--backup` - Backup any files that are changed.
55
+
56
+ ### Special Options
57
+
58
+ * `--[no-]ansi` - Toggle ansi color.
59
+
60
+ * `--debug` - Run in debug mode.
61
+
62
+ * `-h`, `--help` - Display this lovely help message.
63
+
64
+
65
+ ## OUTPUT
66
+
67
+ Regex has three output modes. YAML, JSON and standard text. The standard
68
+ text output is unique in that it utilizes special ASCII characters
69
+ to separate matches and regex groups. ASCII 29, called the *record separator*,
70
+ is used to separate repeat matches. ASCII 30, called the *group separator*, is
71
+ is used to separate regular expression groups.
72
+
73
+
74
+ ## EXAMPLES
75
+
76
+ The following example returns the content between the first `=begin ... =end`
77
+ clause it comes across.
78
+
79
+ $ regex '/=begin.*?\n(.*)\n=end/' sample.rb
80
+
81
+ Instead of the first argument being the regular expresion, we can use the `-s`
82
+ option. This exampe finds the first line starting with a Q.
83
+
84
+ $ regex -s '^Q' sample.txt
85
+
86
+ This example would replace all words starting with an X with an A in all .txt
87
+ files in the current directory.
88
+
89
+ $ regex -g -s '\bX' -r 'A' *.txt
90
+
91
+
92
+ ## COPYRIGHTS
93
+
94
+ Copyright (c) 2009 Thomas Sawyer, Rubyworks
95
+
96
+ Regex is distributable in accordance with the terms of the BSD-2-Clause license.
97
+
@@ -0,0 +1,2 @@
1
+ = Regex
2
+
@@ -0,0 +1,19 @@
1
+ require 'regex'
2
+
3
+ When 'Given a file (((\S+))) containing' do |file, text|
4
+ File.open(file, 'w'){ |f| f << text }
5
+ end
6
+
7
+ When 'invoking the command' do |text|
8
+ text = text.sub(/^\$\s+/, '')
9
+ @out = `#{text}`
10
+ end
11
+
12
+ When 'Should produce' do |text|
13
+ @out.strip.assert == text.strip
14
+ end
15
+
16
+ When 'result in a new file (((\S+))) containing' do |file, text|
17
+ File.read(file).strip.assert == text.strip
18
+ end
19
+
@@ -0,0 +1,26 @@
1
+ == Search and Replace on Files
2
+
3
+ Given a file a.txt containing:
4
+
5
+ This is file a.txt.
6
+ This is an example.
7
+
8
+ And given a file b.txt containing:
9
+
10
+ This is file b.txt.
11
+ This is another example.
12
+
13
+ Then invoking the command:
14
+
15
+ $ regex -s example -r EXAMPLE a.txt b.txt
16
+
17
+ Should result in a new file a.txt containing:
18
+
19
+ This is file a.txt.
20
+ This is an EXAMPLE.
21
+
22
+ And should result in a new file b.txt containing:
23
+
24
+ This is file b.txt.
25
+ This is another EXAMPLE.
26
+
@@ -0,0 +1,31 @@
1
+ == Searching Files
2
+
3
+ Given a file a.txt containing:
4
+
5
+ This is file a.txt.
6
+ This is an example.
7
+
8
+ And given a file b.txt containing:
9
+
10
+ This is file b.txt.
11
+ This is another example.
12
+
13
+ Then invoking the command:
14
+
15
+ $ regex -s example a.txt b.txt
16
+
17
+ Should produce:
18
+
19
+ example
20
+
21
+ In this case it found the first match and returned it.
22
+ To handle a global search we add the `-g` flag.
23
+
24
+ Invoking the command:
25
+
26
+ $ regex -g -s example a.txt b.txt
27
+
28
+ Will give a more complex result.
29
+
30
+ @out.assert == "example\036\nexample\n"
31
+