Browse Source

added python search example

George Jones 1 year ago
parent
commit
57f3d891d1
1 changed files with 22 additions and 0 deletions
  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}")