Skip to content

Commit 63132b5

Browse files
committed
Documentation updates and clean ups.
1 parent 0c59d41 commit 63132b5

File tree

5 files changed

+508
-486
lines changed

5 files changed

+508
-486
lines changed

README.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
regex
22
=====
3-
4-
A Rust library for parsing, compiling, and executing regular expressions.
5-
This particular implementation of regular expressions guarantees execution
6-
in linear time with respect to the size of the regular expression and
7-
search text by using finite automata. In particular, it makes use of both
8-
NFAs and DFAs when matching. Much of the syntax and implementation is inspired
3+
A Rust library for parsing, compiling, and executing regular expressions. Its
4+
syntax is similar to Perl-style regular expressions, but lacks a few features
5+
like look around and backreferences. In exchange, all searches execute in
6+
linear time with respect to the size of the regular expression and search text.
7+
Much of the syntax and implementation is inspired
98
by [RE2](https://github.com/google/re2).
109

1110
[![Build Status](https://travis-ci.org/rust-lang-nursery/regex.svg?branch=master)](https://travis-ci.org/rust-lang-nursery/regex)
@@ -29,7 +28,7 @@ Add this to your `Cargo.toml`:
2928

3029
```toml
3130
[dependencies]
32-
regex = "0.1"
31+
regex = "0.2"
3332
```
3433

3534
and this to your crate root:
@@ -56,9 +55,9 @@ fn main() {
5655
").unwrap();
5756
let caps = re.captures("2010-03-14").unwrap();
5857

59-
assert_eq!("2010", caps.name("year").unwrap());
60-
assert_eq!("03", caps.name("month").unwrap());
61-
assert_eq!("14", caps.name("day").unwrap());
58+
assert_eq!("2010", caps["year"]);
59+
assert_eq!("03", caps["month"]);
60+
assert_eq!("14", caps["day"]);
6261
}
6362
```
6463

@@ -82,9 +81,9 @@ fn main() {
8281
// because the only way for the regex to match is if all of the
8382
// capture groups match. This is not true in general though!
8483
println!("year: {}, month: {}, day: {}",
85-
caps.at(1).unwrap(),
86-
caps.at(2).unwrap(),
87-
caps.at(3).unwrap());
84+
caps.get(1).unwrap().as_str(),
85+
caps.get(2).unwrap().as_str(),
86+
caps.get(3).unwrap().as_str());
8887
}
8988
}
9089
```
@@ -137,8 +136,8 @@ means the main API can't be used for searching arbitrary bytes.
137136
To match on arbitrary bytes, use the `regex::bytes::Regex` API. The API
138137
is identical to the main API, except that it takes an `&[u8]` to search
139138
on instead of an `&str`. By default, `.` will match any *byte* using
140-
`regex::bytes::Regex`, while `.` will match any encoded Unicode *codepoint*
141-
using the main API.
139+
`regex::bytes::Regex`, while `.` will match any *UTF-8 encoded Unicode scalar
140+
value* using the main API.
142141

143142
This example shows how to find all null-terminated strings in a slice of bytes:
144143

@@ -152,7 +151,7 @@ let text = b"foo\x00bar\x00baz\x00";
152151
// The unwrap is OK here since a match requires the `cstr` capture to match.
153152
let cstrs: Vec<&[u8]> =
154153
re.captures_iter(text)
155-
.map(|c| c.name("cstr").unwrap())
154+
.map(|c| c.name("cstr").unwrap().as_bytes())
156155
.collect();
157156
assert_eq!(vec![&b"foo"[..], &b"bar"[..], &b"baz"[..]], cstrs);
158157
```
@@ -211,9 +210,9 @@ fn main() {
211210
let re = regex!(r"(\d{4})-(\d{2})-(\d{2})");
212211
let caps = re.captures("2010-03-14").unwrap();
213212

214-
assert_eq!("2010", caps.at(1).unwrap());
215-
assert_eq!("03", caps.at(2).unwrap());
216-
assert_eq!("14", caps.at(3).unwrap());
213+
assert_eq!("2010", caps[1]);
214+
assert_eq!("03", caps[2]);
215+
assert_eq!("14", caps[3]);
217216
}
218217
```
219218

0 commit comments

Comments
 (0)