aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/lux/regex.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/lux/regex.lux')
-rw-r--r--stdlib/source/lux/regex.lux58
1 files changed, 58 insertions, 0 deletions
diff --git a/stdlib/source/lux/regex.lux b/stdlib/source/lux/regex.lux
index e3cd95811..417abc086 100644
--- a/stdlib/source/lux/regex.lux
+++ b/stdlib/source/lux/regex.lux
@@ -421,6 +421,64 @@
## [Syntax]
(syntax: #export (regex [pattern syntax;text])
+ {#;doc (doc "Create lexers using regular-expression syntax."
+ "For example:"
+
+ "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(.)(.)")
+ )}
(do @
[current-module compiler;current-module-name]
(case (&;run (&;&_ (regex^ current-module) &;end) pattern)