Skip to content

Commit

Permalink
Merge pull request #1 from newsboat/feature/update-readme
Browse files Browse the repository at this point in the history
Make the README useful
  • Loading branch information
Minoru authored Jan 6, 2025
2 parents d9105c3 + f8810f1 commit 705ce62
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
authors = ["Alexander Batischev <[email protected]>"]
edition = "2021"
license = "MIT"
# ==============
readme = "README.md"
description = """ Safe wrapper for [POSIX regular expressions API][regex-h] (provided by libc on POSIX-compliant OSes).
Part of libnewsboat lib dependencies"""
description = "Safe wrapper for POSIX regular expressions API"
homepage = "https://github.com/newsboat/regex-rs"
repository = "https://github.com/newsboat/regex-rs"
keywords = ["posix", "regex", "bindings"]
categories = ["api-bindings", "os"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,31 @@
# regex-rs (part of libnewsboat library)
# regex-rs: safe wrapper for [POSIX regular expressions API][regex-h] (provided by libc on POSIX-compliant OSes)

__Disclaimer:__ This project is part of [Newsboat](https://github.com/newsboat/newsboat) Rust libraries, I'm not it's author - merely maintaining up to date versions on Crates.io.
[regex-h]: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/basedefs/regex.h.html#tag_13_37

## Description
Example usage:

Safe wrapper for [POSIX regular expressions API][regex-h] (provided by libc on POSIX-compliant OSes).
```rust
use regex_rs::*;

let pattern = "This( often)? repeats time and again(, and again)*\\.";
let compilation_flags = CompFlags::EXTENDED;
let regex = Regex::new(pattern, compilation_flags)
.expect("Failed to compile pattern as POSIX extended regular expression");

let input = "This repeats time and again, and again, and again.";
// We're only interested in the first match, i.e. the part of text
// that's matched by the whole regex
let max_matches = 1;
let match_flags = MatchFlags::empty();
let matches = regex
.matches(input, max_matches, match_flags)
.expect("Error matching input against regex");

// Found a match
assert_eq!(matches.len(), 1);

// Match spans from the beginning to the end of the input
assert_eq!(matches[0].start_pos, 0);
// `end_pos` holds one-past-the-end index
assert_eq!(matches[0].end_pos, input.len());
```
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//!
//! [regex-h]: https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/basedefs/regex.h.html#tag_13_37
//!
//! Example usage:
//!
//! ```
//! use regex_rs::*;
//!
Expand Down

0 comments on commit 705ce62

Please sign in to comment.