Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kstep/regindex
Index &str with regex in Rust (experiment)
https://github.com/kstep/regindex
Last synced: about 2 months ago
JSON representation
Index &str with regex in Rust (experiment)
- Host: GitHub
- URL: https://github.com/kstep/regindex
- Owner: kstep
- License: mit
- Created: 2015-03-20T08:08:50.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-03-21T12:53:28.000Z (almost 10 years ago)
- Last Synced: 2024-10-11T23:46:58.680Z (2 months ago)
- Language: Rust
- Size: 148 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# regindex
Index &str with regex in Rust (experiment)Inspired by Ruby syntax for regexp matching using indexing.
Examples:
```rust
#[macro_use]
use regindex::ReIdx;fn main() {
let haystack = "abbcccdddd";
let found = &haystack[ri!["cd+"]]; // == "cdddd"// or more verbose way without macros:
let found = &haystack[ReIdx::new("bc+")]; // == "bccc"// if nothing found or error, it returns empty slice:
let found = &haystack[ReIdx::new("(c+")]; // == "" (invalid regexp)
let found = &haystack[ri!["(c+"]]; // but this will panic!
let found = &haystack[ReIdx::new("ax+")]; // == "" (no match found)// you can also wrap regex:
let re = Regex::new("ab+");
let found = &haystack[ReIdx::from_regex(re)]; // == "abb"
}
```