pub fn fg_green(text: String) -> String
Expand description
Formats the given text with green foreground color.
Examples found in repository?
examples/phone_number.rs (lines 46-50)
3fn main() {
4 // \s*(?:\+?[0-9]{10}|\(\d{3}\)|\d{3})(?:[-\s]?\d{3}[-\s]?\d{4})?\s*$
5 let builder = RegexBuilder::new()
6 .start_of_line()
7 .zero_or_more(RegexBuilder::new().whitespace())
8 .group(
9 RegexBuilder::new()
10 .alternative(
11 RegexBuilder::new()
12 .alternative(
13 RegexBuilder::new()
14 .zero_or_one(RegexBuilder::new().literal('+'))
15 .exact_repetitions(RegexBuilder::new().range_character_class('0', '9'), 10),
16 RegexBuilder::new()
17 .literal('(')
18 .exact_repetitions(RegexBuilder::new().digit(), 3)
19 .literal(')'),
20 ),
21 RegexBuilder::new().exact_repetitions(RegexBuilder::new().digit(), 3)
22
23 )
24 )
25 .zero_or_one(
26 RegexBuilder::new()
27 .group(
28 RegexBuilder::new()
29 .zero_or_one(
30 RegexBuilder::new()
31 .dash_space_character_class()
32 )
33 .exact_repetitions(RegexBuilder::new().digit(), 3)
34 .zero_or_one(
35 RegexBuilder::new()
36 .dash_space_character_class()
37 )
38 .exact_repetitions(RegexBuilder::new().digit(), 4)
39 )
40 )
41 .zero_or_more(RegexBuilder::new().whitespace())
42 .end_of_line();
43
44 let regex_ = builder.to_regex_or_panic();
45 println!("{}", builder.build());
46 println!("{}", ansi::fg_green(
47 format!(
48 "{}", regex_.is_match("1234567890")
49 )
50 ));
51 println!("{}", ansi::fg_green(
52 format!(
53 "{}", regex_.is_match("(123) 456-7890")
54 )
55 ));
56 println!("{}", ansi::fg_green(
57 format!(
58 "{}", regex_.is_match("123-456-7890")
59 )
60 ));
61 println!("{}", ansi::fg_green(
62 format!(
63 "{}", regex_.is_match("123 456 7890")
64 )
65 ));
66 println!("{}", ansi::fg_green(
67 format!(
68 "{}", regex_.is_match("1234567890")
69 )
70 ));
71}