Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/re_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ macro_rules! define_builder {
///
/// If the pattern is invalid, then an error will be returned when
/// `build` is called.
pub fn new(pattern: &str) -> RegexBuilder {
pub fn new<T: Into<String>>(pattern: T) -> RegexBuilder {
let mut builder = RegexBuilder(RegexOptions::default());
builder.0.pats.push(pattern.to_owned());
builder.0.pats.push(pattern.into());
builder
}

Expand Down
26 changes: 25 additions & 1 deletion src/re_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,31 @@ impl Regex {
/// to search, split or replace text in a string.
///
/// If an invalid expression is given, then an error is returned.
pub fn new(re: &str) -> Result<Regex, Error> {
///
/// # Example
///
/// Create a new Regex using a &str.
///
/// ```rust
/// # use regex::bytes::Regex;
/// # fn main() {
/// let regex: &str = r"\b\w{13}\b";
/// Regex::new(regex);
/// # }
/// ```
///
/// # Example
///
/// Create a new Regex using a String.
///
/// ```rust
/// # use regex::bytes::Regex;
/// # fn main() {
/// let regex: String = r"\b\w{13}\b".to_string();
/// Regex::new(regex);
/// # }
/// ```
pub fn new<T: Into<String>>(re: T) -> Result<Regex, Error> {
RegexBuilder::new(re).build()
}

Expand Down
26 changes: 25 additions & 1 deletion src/re_unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,31 @@ impl Regex {
/// to search, split or replace text in a string.
///
/// If an invalid expression is given, then an error is returned.
pub fn new(re: &str) -> Result<Regex, Error> {
///
/// # Example
///
/// Create a new Regex using a &str.
///
/// ```rust
/// # use regex::bytes::Regex;
/// # fn main() {
/// let regex: &str = r"\b\w{13}\b";
/// Regex::new(regex);
/// # }
/// ```
///
/// # Example
///
/// Create a new Regex using a String.
///
/// ```rust
/// # use regex::bytes::Regex;
/// # fn main() {
/// let regex: String = r"\b\w{13}\b".to_string();
/// Regex::new(regex);
/// # }
/// ```
pub fn new<T: Into<String>>(re: T) -> Result<Regex, Error> {
RegexBuilder::new(re).build()
}

Expand Down