summaryrefslogtreecommitdiff
path: root/regex.py
diff options
context:
space:
mode:
Diffstat (limited to 'regex.py')
-rw-r--r--regex.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/regex.py b/regex.py
new file mode 100644
index 0000000..5573160
--- /dev/null
+++ b/regex.py
@@ -0,0 +1,36 @@
+import re
+
+# count=0
+# # pattern=re.compile("ab")
+# # matcher=pattern.finditer("ababababa")
+# matcher=re.finditer("ab","abababababab")
+# for match in matcher:
+# count+=1
+# print(f"{match.start()} ... {match.end()} ... {match.group()}")
+# print(f"total count is {count}")
+
+# x='[abc]'
+# x='[^abc]'
+# x='[a-z]'
+# x='[0-9]'
+# x='[a-zA-Z0-9]'
+# x='[^a-zA-Z0-9]'
+
+matcher=re.finditer(x,"asdASKJHabc!@#!133)")
+for match in matcher:
+ print(f"{match.start()} ... {match.end()} ... {match.group()}")
+
+'''
+Predefined character classes
+\s space
+\S not space
+\d digit
+\D not digit
+\w word (non special characters)
+\W special characters
+. all symbols
+'''
+
+matcher=re.finditer(x, "asd7 asdasd*)( ASH")
+for match in matcher:
+ print(f"{match.start()} ... {match.end()} ... {match.group()}")