File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11# regex using module re to match patterns
2+
3+ '''
4+ MetaCharacters
5+ Metacharacters are characters that are interpreted in a special way by a RegEx engine. Here's a list of metacharacters:
6+
7+ [] . ^ $ * + ? {} () \ |
8+
9+ Here, [abc] will match if the string you are trying to match contains any of the a, b or c.
10+
11+ You can also specify a range of characters using - inside square brackets.
12+
13+ [a-e] is the same as [abcde].
14+ [1-4] is the same as [1234].
15+ [0-39] is the same as [01239].
16+
17+ You can complement (invert) the character set by using caret ^ symbol at the start of a square-bracket.
18+
19+ [^abc] means any character except a or b or c.
20+ [^0-9] means any non-digit character.
21+ '''
222import re
323pattern = '^a...s$'
424test_string = 'abyss'
727if result :
828 print ('Pattern matched' )
929else :
10- print ('Pattern not matched' )
30+ print ('Pattern not matched' )
You can’t perform that action at this time.
0 commit comments