aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/data/text/regex.lux
blob: 7d8ecfe9754c247e797428fa23475bbb17d782bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
(.require
 [library
  [lux (.except pattern)
   ["$" documentation (.only documentation:)]
   [data
    [text (.only \n)
     ["%" \\format (.only format)]]]
   [macro
    ["[0]" template]]]]
 [\\library
  ["[0]" /]])

(documentation: /.regex
  "Create lexers using regular-expression syntax."
  ["Literals"
   (regex "a")]
  ["Wildcards"
   (regex ".")]
  ["Escaping"
   (regex "\.")]
  ["Character classes"
   (regex "\d")
   (regex "\p{Lower}")
   (regex "[abc]")
   (regex "[a-z]")
   (regex "[a-zA-Z]")
   (regex "[a-z&&[def]]")]
  ["Negation"
   (regex "[^abc]")
   (regex "[^a-z]")
   (regex "[^a-zA-Z]")
   (regex "[a-z&&[^bc]]")
   (regex "[a-z&&[^m-p]]")]
  ["Combinations"
   (regex "aa")
   (regex "a?")
   (regex "a*")
   (regex "a+")]
  ["Specific amounts"
   (regex "a{2}")]
  ["At least"
   (regex "a{1,}")]
  ["At most"
   (regex "a{,1}")]
  ["Between"
   (regex "a{1,2}")]
  ["Groups"
   (regex "a(.)c")
   (regex "a(b+)c")
   (regex "(\d{3})-(\d{3})-(\d{4})")
   (regex "(\d{3})-(?:\d{3})-(\d{4})")
   (regex "(?<code>\d{3})-\k<code>-(\d{4})")
   (regex "(?<code>\d{3})-\k<code>-(\d{4})-\0")
   (regex "(\d{3})-((\d{3})-(\d{4}))")]
  ["Alternation"
   (regex "a|b")
   (regex "a(.)(.)|b(.)(.)")])

(documentation: /.pattern
  "Allows you to test text against regular expressions."
  [(case some_text
     (pattern "(\d{3})-(\d{3})-(\d{4})"
              [_ country_code area_code place_code])
     do_some_thing_when_number

     (pattern "\w+")
     do_some_thing_when_word

     _
     do_something_else)])

(.def .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..regex
             ..pattern
             ($.default /.incorrect_quantification)]
            []))