例によって標準モジュールにはない。
成果物
crates.io
クレート新規作成
$ cargo new regex_hello --bin
Cargo.toml
[dependencies] regex = "1"
初回ビルドでダウンロード&コンパイル。2分かかった。
$ cargo build Updating crates.io index Compiling memchr v2.2.1 Compiling lazy_static v1.3.0 Compiling ucd-util v0.1.5 Compiling utf8-ranges v1.0.3 Compiling thread_local v0.3.6 Compiling regex-syntax v0.6.10 Compiling aho-corasick v0.7.4 Compiling regex v1.2.0 Compiling regex_hello v0.1.0 (/tmp/work/Rust.Regex.20190729131335/src/0/regex_hello) Finished dev [unoptimized + debuginfo] target(s) in 2m 10s
main.rs
use regex::Regex; fn main() { let re = Regex::new(r"(?x) (?P<year>\d{4}) # the year - (?P<month>\d{2}) # the month - (?P<day>\d{2}) # the day ").unwrap(); let caps = re.captures("2010-03-14").unwrap(); assert_eq!("2010", &caps["year"]); assert_eq!("03", &caps["month"]); assert_eq!("14", &caps["day"]); }
$ cargo run
エラーなし。成功!
ちなみに、一行で表現すると以下。
let re = Regex::new(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})").unwrap();
対象環境
- Raspbierry pi 3 Model B+
- Raspbian stretch 9.0 2018-11-13
- bash 4.4.12(1)-release
- rustc 1.36.0 (a53f9df32 2019-07-03)
- cargo 1.36.0 (c4fcfb725 2019-05-15)
$ uname -a Linux raspberrypi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l GNU/Linux
前回まで
- Rust自習(じゃんけんゲーム1)
- Rust自習(双方向リスト1)
- Rust自習(単方向リスト1)
- Rust自習(単方向リスト2)
- Rust自習(単方向リスト3)
- Rust自習(単方向リスト4)
- Rust自習(単方向リスト5)
- Rust自習(単方向リスト6)
- Rust自習(単方向リスト7)
- Rust自習(リストのインタフェースを考える)
- Rust自習(連結リスト1)
- Rust自習(連結リスト2)
- Rust自習(連結リスト3)
- Rust自習(連結リスト4)
- Rust自習(連結リストの取得系インタフェース考察)
- Rust自習(連結リスト5)
- Rust自習(連結リストの取得系インタフェース考察2)
- Rust自習(連結リスト6)
- Rust自習(連結リスト7)
- Rust自習(連結リスト8)
- Rust自習(連結リスト9)
- Rust自習(変数名でイテレートする方法)
- Rust自習(iter、iter_mut実装方法)
- Rust自習(連結リスト10)
- Rust自習(rev()実装できず)
- Rust自習(cycle()実装できず)
- Rust自習(じゃんけんゲーム2)
- Rust自習(じゃんけんゲーム3)
- Rust自習(じゃんけんゲーム4)
- Rust自習(じゃんけんゲーム5)
- Rust自習(じゃんけんゲーム6)
- Rust自習(じゃんけんゲーム7)
- Rust自習(じゃんけんゲーム8)
- Rustのアップデート(rustup update)
- Rust自習(SQLite3 1)
- Rust自習(SQLite3 2)
- Rust自習(SQLite3 3)
- Rust自習(日時 1 chrono)
- Rust自習(日時 2 chrono)
- Rust自習(日時 3 chrono)
- Rust自習(日時 4 chrono)
- Rust自習(日時 5 chrono)
- Rust自習(日時 6 chrono)
- Rust自習(日時 7 chrono)
- Rust自習(std::time::SystemTime)
- Rust自習(std::time::Instant)
- Rust自習(std::time::Duration)
- Rust自習(シリアライズ serde 1)
- JSON5とは?
- Rust自習(シリアライズ serde 2 JSON5)
- Rust自習(シリアライズ serde 3 chrono日時型変換)
- Rust自習(diesel 1 SQLite3 ORM)
- Rust自習(diesel 2 SQLite3 ORM)
- Rust自習(diesel 3 SQLite3 ORM)
- Rust自習(diesel 4 SQLite3 ORM)
- Rust自習(diesel 5 SQLite3 ORM)
- Rust自習(diesel 6 SQLite3 ORM)
- Rust自習(diesel 7 SQLite3 ORM serde,chrono)
- Rust自習(diesel 8 SQLite3 ORM serde,chrono)