Enhance Documentation for replace.rs and groups.rs with Practical Examples #18

Closed
opened 2026-03-11 18:13:13 +03:00 by NiXTheDev · 0 comments
NiXTheDev commented 2026-03-11 18:13:13 +03:00 (Migrated from github.com)

Goal: Make it easier for users to understand how to use replacement strings and capture groups.

Currently, replace.rs and groups.rs have minimal doc comments. Add detailed examples showing:

  • Using \G to reference the entire match in replacements.
  • Named group access in replacement strings.
  • Accessing groups in the Match object.

Example for replace.rs:

/// # Example
/// ```
/// use ogex::Replacement;
///
/// let repl = Replacement::new(r"[\G]").unwrap();
/// let result = repl.replace("hello world", "hello");
/// assert_eq!(result, "[hello] world");
/// ```

Example for groups.rs:

/// # Example
/// ```
/// use ogex::Regex;
///
/// let re = Regex::new(r"(first:\w+) (second:\w+)").unwrap();
/// let m = re.find("hello world").unwrap();
/// assert_eq!(m.named_group_str("first"), Some("hello"));
/// assert_eq!(m.named_group_str("second"), Some("world"));
/// ```

Implementation:

  • Add doc comments with # Example sections, and ensure they are tested with cargo test.
**Goal**: Make it easier for users to understand how to use replacement strings and capture groups. Currently, `replace.rs` and `groups.rs` have minimal doc comments. Add detailed examples showing: - Using `\G` to reference the entire match in replacements. - Named group access in replacement strings. - Accessing groups in the `Match` object. **Example for [replace.rs](https://raw.githubusercontent.com/NiXTheDev/Ogex/refs/heads/release/ogex/src/replace.rs)**: ```rust /// # Example /// ``` /// use ogex::Replacement; /// /// let repl = Replacement::new(r"[\G]").unwrap(); /// let result = repl.replace("hello world", "hello"); /// assert_eq!(result, "[hello] world"); /// ``` ``` **Example for [groups.rs](https://raw.githubusercontent.com/NiXTheDev/Ogex/refs/heads/release/ogex/src/groups.rs)**: ```rust /// # Example /// ``` /// use ogex::Regex; /// /// let re = Regex::new(r"(first:\w+) (second:\w+)").unwrap(); /// let m = re.find("hello world").unwrap(); /// assert_eq!(m.named_group_str("first"), Some("hello")); /// assert_eq!(m.named_group_str("second"), Some("world")); /// ``` ``` **Implementation**: - Add doc comments with # Example sections, and ensure they are tested with cargo test.
Sign in to join this conversation.
No description provided.