Explorar o código

added python search example

George Jones hai 1 ano
pai
achega
57f3d891d1
Modificáronse 1 ficheiros con 22 adicións e 0 borrados
  1. 22 0
      home/public/snippits/python/re_search.py

+ 22 - 0
home/public/snippits/python/re_search.py

@@ -0,0 +1,22 @@
+#! /usr/bin/env python
+# Simple regex examples
+
+import re
+
+foo="The foo in bar falls in Maine, mainly"
+
+if re.search("foo",foo):
+    print(f"'foo' is in {foo}")
+else:
+    print(f"'foo' is NOT in {foo}")
+
+if re.search("bar",foo):
+    print(f"'bar' is in {foo}")
+else:
+    print(f"'bar' is NOT in {foo}")
+
+
+if re.search("^The",foo):
+    print(f"'The' is at the start of {foo}")
+else:
+    print(f"'The' is NOT at the start of {foo}")