Преглед на файлове

added python search example

George Jones преди 1 година
родител
ревизия
57f3d891d1
променени са 1 файла, в които са добавени 22 реда и са изтрити 0 реда
  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}")