← nimrepo

add files

7118b575689b0f40959fed05f11be8b4826ff424 · ovidiucs · Jan 29, 2019 22:08

+35 −1 · 2 files changed

  • regular_expressions.nim +34 −0
  • tuples.nim +1 −1
diff --git a/regular_expressions.nim b/regular_expressions.nim
new file mode 100644
index 0000000..880a5a6
--- /dev/null
+++ b/regular_expressions.nim
@@ -0,0 +1,34 @@
+# Copyright 2019.
+import terminal
+from strutils import repeat
+#---
+
+#import re
+import regex
+
+echo '-'.repeat(40)
+
+styledEcho fgRed,
+    "Regular expressions"
+echo """
+1. use 're' stdlib
+* PCRE syntax is used when using this library
+* man pcresyntax
+2. use 'nim-regex' (nimble install regex)
+* https://nitely.github.io/nim-regex/
+"""
+echo """
+import re or import regex
+
+let
+  text =  " " " Mary had a little lamb." " "
+  rgx = re"(?i)mary"
+
+echo text.replace(rgx, "Mama lamb")
+"""
+let
+  text = """Mary had a little lamb."""
+  rgx = re"(?i)mary"
+
+echo text.replace(rgx, "Mama lamb")
+
diff --git a/tuples.nim b/tuples.nim
index fa11e97..0e3053d 100644
--- a/tuples.nim
+++ b/tuples.nim
@@ -1,5 +1,5 @@
 import terminal
-from strutils import repeat
+    from strutils import repeat
 from strformat import fmt
 from typetraits import arity
 from os import splitFile