Explorar el Código

added python search example

George Jones hace 1 año
padre
commit
57f3d891d1
Se han modificado 1 ficheros con 22 adiciones y 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}")