sedregex
[Release docs]
[Master docs]
A simple sed-like library that uses regex under the hood.
Usage
There are basically two public interfaces which you can enjoy:
- [
find_and_replace
], which is useful for one-time processing of a bunch of commands,
- and [
ReplaceCommand
] when you need to run the same command multiple times.
Examples
Let's jump straight to the examples!
use sedregex::{find_and_replace, ReplaceCommand};
fn main() {
assert_eq!(
"Please stop wuts oh wut.",
ReplaceCommand::new("s/lol/wut/ig").unwrap().execute("Please stop Lols oh lol."),
);
assert_eq!(
"Please stop nos oh no.",
find_and_replace("Please stop Lols oh lol.", &["s/lol/wut/ig", "s/wut/no/g"]).unwrap()
);
assert_eq!(
"Please stop wuts oh wut.",
find_and_replace("Please stop Lols oh lol.", &["/lol/wut/ig"]).unwrap()
);
assert_eq!(
"Please stop Lols oh wut.",
find_and_replace("Please stop Lols oh lol.", &["/lol/wut/"]).unwrap()
);
assert_eq!(
"Please stop Lols oh wut.",
find_and_replace("Please stop Lols oh lol.", &["/lol/wut"]).unwrap()
);
assert_eq!(
r"Please stop wut/s oh wut/.",
find_and_replace("Please stop Lols oh lol.", &[r"s/lol/wut\//gi"]).unwrap()
);
assert_eq!(
"Second, First",
find_and_replace(
"First, Second",
&[r"s/(?P<first>[^,\s]+),\s+(?P<last>\S+)/$last, $first"],
).unwrap()
);
assert_eq!(
"Some weird typo",
find_and_replace("Some wierd typo", &[r"s/ie/ei/"]).unwrap()
);
}
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.