All Projects → softprops → Recap

softprops / Recap

Licence: mit
deserialize typed structures from regex captures

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Recap

Hackvault
A container repository for my public web hacks!
Stars: ✭ 1,364 (+910.37%)
Mutual labels:  regex
Proposal Regexp Unicode Property Escapes
Proposal to add Unicode property escapes `\p{…}` and `\P{…}` to regular expressions in ECMAScript.
Stars: ✭ 112 (-17.04%)
Mutual labels:  regex
Ffind
A sane replacement for find
Stars: ✭ 124 (-8.15%)
Mutual labels:  regex
Orchestra
One language to be RegExp's Successor. Visually readable and rich, technically safe and extended, naturally scalable, advanced, and optimized
Stars: ✭ 103 (-23.7%)
Mutual labels:  regex
Typical
Typical: Fast, simple, & correct data-validation using Python 3 typing.
Stars: ✭ 111 (-17.78%)
Mutual labels:  serde
Lens Regex Pcre
Text lenses using PCRE regexes
Stars: ✭ 116 (-14.07%)
Mutual labels:  regex
Anylint
Lint anything by combining the power of Swift & regular expressions.
Stars: ✭ 100 (-25.93%)
Mutual labels:  regex
Sammler
A tool to extract useful data from documents
Stars: ✭ 131 (-2.96%)
Mutual labels:  regex
Homebridge Http Switch
Powerful http switch for Homebridge: https://github.com/homebridge/homebridge
Stars: ✭ 111 (-17.78%)
Mutual labels:  regex
Serde urlencoded
x-www-form-urlencoded meets Serde
Stars: ✭ 120 (-11.11%)
Mutual labels:  serde
Command Line Text Processing
⚡ From finding text to search and replace, from sorting to beautifying text and more 🎨
Stars: ✭ 9,771 (+7137.78%)
Mutual labels:  regex
Blog
我的日记
Stars: ✭ 110 (-18.52%)
Mutual labels:  regex
Grepbugs
A regex based source code scanner.
Stars: ✭ 118 (-12.59%)
Mutual labels:  regex
Boswatch
Python Script to process input data from rtl_fm and multimon-NG - multiple Plugin support
Stars: ✭ 101 (-25.19%)
Mutual labels:  regex
Kaggle Quora Dup
Solution to Kaggle's Quora Duplicate Question Detection Competition
Stars: ✭ 129 (-4.44%)
Mutual labels:  regex
Simpleaudioindexer
Searching for the occurrence seconds of words/phrases or arbitrary regex patterns within audio files
Stars: ✭ 100 (-25.93%)
Mutual labels:  regex
Learn Regex Zh
🇨🇳 翻译: 学习正则表达式的简单方法
Stars: ✭ 1,772 (+1212.59%)
Mutual labels:  regex
Readable Pylint Messages
List of pylint human readable message ids and dev readable codes
Stars: ✭ 134 (-0.74%)
Mutual labels:  regex
Bee.js
javaScript常用工具类
Stars: ✭ 130 (-3.7%)
Mutual labels:  regex
Js Regular Expression Awesome
📄我收藏的正则表达式大全,欢迎补充
Stars: ✭ 120 (-11.11%)
Mutual labels:  regex

recap Build Status Coverage Status Software License crates.io Released API docs Master API docs

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 (?P<name-of-capture-group>some-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.

[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

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

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

fn main() -> Result<(), Box<dyn Error>> {
    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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].