百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
R

recap

> 编程语言
开源

从 regex 捕获中去除输入结构

176 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

从 regex 捕获中去除输入结构

recap

deserialize named capture groups into typesafe structs

Recap is provides what envy provides for environment variables, for named capture groups. Named regex capture groups are like any other regex capture group but have the extra property that they are associated with name. i.e (?Psome-pattern)

who is this for

You may find this crate useful for cases where your application needs to extract information from string input provided by a third party that has a loosely structured format.

A common usecase for this is when you are dealing with log file data that was not stored in a particular structured format like JSON, but rather in a format that can be represented with a pattern.

You may also find this useful parsing other loosely formatted data patterns.

This crate would be less appropriate for cases where your input is provided in a more structured format, like JSON. I recommend using a crate like serde-json for those cases instead.

install

Add the following to your Cargo.toml file.

toml
[dependencies]
recap = "0.1"

usage

A typical recap usage looks like the following. Assuming your Rust program looks something like this...

These examples use Serde's derive feature

rust
use recap::Recap;
use serde::Deserialize;
use std::error::Error;

#[derive(Debug, Deserialize, Recap)]
#[recap(regex = r#"(?x)
    (?P\d+)
    \s+
    (?Ptrue|false)
    \s+
    (?P\S+)
  "#)]
struct LogEntry {
    foo: usize,
    bar: bool,
    baz: String,
}

fn main() -> Result> {
    let logs = r#"1 true hello
  2 false world"#;

    for line in logs.lines() {
        let entry: LogEntry = line.parse()?;
        println!("{:#?}", entry);
    }

    Ok(())
}

Consider this crate a cousin of envy, a crate for deserializing environment variables into typesafe structs.

Doug Tangren (softprops) 2019

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustregexserde

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言