summaryrefslogtreecommitdiff
path: root/regex.py
diff options
context:
space:
mode:
authoranand <anand.panchdhari@gmail.com>2025-12-13 17:06:22 +0530
committeranand <anand.panchdhari@gmail.com>2025-12-13 17:06:22 +0530
commitbd3664c6315dca15d15bdf4d4a6342b2131e041c (patch)
tree1c6e326bc935e4bd78490f7f495757198dd826c2 /regex.py
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()}")