#regex #phone-number #string #numbers #date #find #email

commonregex

Rust版本的CommonRegex。在字符串中查找所有时间、日期、链接、电话号码、电子邮件、IP地址、价格、十六进制颜色和信用卡号。我们做了艰苦的工作,所以您不必。

1个不稳定版本

0.2.0 2019年2月5日
0.1.4 2019年2月5日

文本处理类别中排名876

Download history 2883/week @ 2024-03-13 2622/week @ 2024-03-20 1912/week @ 2024-03-27 3713/week @ 2024-04-03 2207/week @ 2024-04-10 2834/week @ 2024-04-17 3682/week @ 2024-04-24 1748/week @ 2024-05-01 1736/week @ 2024-05-08 2414/week @ 2024-05-15 1598/week @ 2024-05-22 2542/week @ 2024-05-29 2503/week @ 2024-06-05 1823/week @ 2024-06-12 1450/week @ 2024-06-19 791/week @ 2024-06-26

每月下载量7,046

MIT许可证

20KB
297

CommonRegexRust

CommonRegex的Rust版本

在字符串中查找大量常见信息。

欢迎提交拉取请求!

请注意,目前仅针对英语/美国。

Build Status

安装

使用Cargo通过

cargo install commonregex

或使用Crates.toml

[package]
name = <package-name>
version = <version>
authors = [<you>]

[dependencies]
commonregex = "0.2.0"

然后在终端上运行cargo build

API

您可以通过构造函数传递一个字符串来创建一个CommonRegex对象,并使用对象的字段来访问匹配项和其他字符串(作为参数传递)的匹配项的方法,或者不传递字符串到构造函数,只使用方法。

可能属性及其对应方法

  • dates: dates(text)
  • times: times(text: &str)
  • phones: phones(text: &str)
  • phones_with_exts: phones_with_exts(text: &str)
  • links: links(text: &str)
  • emails: emails(text: &str)
  • ipv4s: ips(text: &str)
  • ipv6s: ipv6s(text: &str)
  • prices: prices(text: &str)
  • hex_colors: hex_colors(text: &str)
  • credit_cards: credit_cards(text: &str)
  • visas: visas(text: &str)
  • mastercards: mastercards(text: &str)
  • btc_addresses: btc_addresses(text: &str)
  • street_addresses: street_addresses(text: &str)
  • zip_codes: zip_codes(text: &str)
  • po_boxs: po_boxs(text: &str)
  • ssns: ssns(text: &str)
  • md5s: md5s(text: &str)
  • sha1s: sha1s(text: &str)
  • sha2s: sha2s(text: &str)
  • guids: guids(text: &str)
  • isbn13s: isbn13s(text: &str)
  • isbn10s: isbn10s(text: &str)
  • mac_addresses: mac_addresses(text: &str)
  • ibans: ibans(text: &str)
  • gitrepos: gitrepos(text: &str)
  • 以上所有:CommonRegex(text: &str)
  • 自定义:parse(regex: &str, text: &str)

示例

extern crate commonregex;

let text = 'John, please get that article on www.linkedin.com to me by 5:00PM 
on Jan 9th 2012. 4:00 would be ideal, actually. If you have any 
questions, You can reach me at (519)-236-2723x341 or get in touch with
my associate at harold.smith@gmail.com';

let parsed =  commonregex::common_regex(text);
println!("{:?}", parsed);
/* prints CommonRegex { dates: ["Jan 9th 2012"], times: ["5:00PM", "4:00 "], phones: ["(519)-236-2723"], phones_with_exts: ["(519)-236-2723x341"], links: ["www.linkedin.com", "[email protected]"], emails: ["[email protected]"], ipv4s: [], ipv6s: [], prices: [], hex_colors: ["201", "dea", "eac", "519", "236", "272", "341"], credit_cards: [], visas: [], mastercards: [], btc_addresses: [], street_addresses: [], zip_codes: [], po_boxs: [], ssns: [], md5s: [], sha1s: [], sha2s: [], guids: [], isbn13s: [], isbn10s: [], mac_addresses: [], ibans: [], gitrepos: [] } */
println!("{:?}", parsed.dates);
//prints ["Jan 9th 2012"]
println!("{:?}", parsed.times);
//prints ["5:00PM", "4:00"]
println!("{:?}",parsed.phones);
//prints ["(012)-345-6789"]
println!("{:?}",parsed.links);
//prints ["www.linkedin.com"]
println!("{:?}",parsed.emails);
//prints ["[email protected]"]

或者,您也可以生成一个单个CommonRegex实例,并使用它来解析多个文本段。

println!("{:?}",commonregex::times("When are you free? Do you want to meet up for coffee at 4:00?"));
//prints ["4:00"]
println!("{:?}",commonregex::prices("They said the price was $5,000.90, actually it is $3,900.5. It\'s $1100.4 less, can you imagine this?"));
//prints ["$5,000.90", "$3,900.5", "$110"]
println!("{:?}",commonregex::ipv6s("The IPv6 address for localhost is 0:0:0:0:0:0:0:1, or alternatively, ::1."));
//prints ["0:0:0:0:0:0:0:1", "::1"]

CommonRegex端口

有其他语言的CommonRegex端口,请参见这里

依赖关系

约2-3MB
约53K SLoC