Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python regex

# You need to - (import re)
# ^		    - Matches the beginning of the line
# $		    - Matches the end of the line
# .		    - Matches any character
# s	    - Matches whitespace
# S	    - Matches any non-whitespace character
# *		    - Repeat a character zero or more times
# *?	    - Repeat a character zero or more times (non-greedy)
# +		    - Repeat a character one or more times
# +?	    - Repeat a character one or more times (non-greedy)
# [aeiou]	- Matches a single character in the listed set
# [^XYZ]	- Matches a single character not in the listed set
# [a-z0-9]	- The set of characters can include a range
# (			- Indicates where string extraction is to start
# )			- Indicates where string extraction is to end

1. A fixed string -> abc123
2. Arbitrary repetition -> a*b ( "*" means that you can have an arbitrary
								number (possibly 0) of the previous char
3. Repeat character at least once -> a+b # ab, aaaab
4. Repeat character at most once -> a?b # b, ab
5. Repeat a character a fixed number of timers -> a{5} # aaaaa
6. Repeat a pattern a fixed number of times -> (a*b){3} # baabab, ababaaaab
7. Repeat a character or pattern a variable number of times -> a{2,4} # aa, aaa, aaaa
8. Choice of several characters -> [ab]c # ac, bc
9. Arbitrary mixture of several characters -> [ab]*c # c, aac, abbac
10. Ranges of characters -> [A-H][a-z]* # Aasdfalsd, Hb, G 
11. Characters OTHER than particular one -> [^AB] # C, D
12. Choice of several expressions -> Dr|Mr|Ms|Mrs # Dr, Mr, Mrs, Ms
13. Nesting expressions -> ([A-Z][a-z][0-9])* # A, AzSDFcvfg
14. Start of a line -> ^ab
15. End of a line -> ab$

#Type of pattern
1. Special characters -> [ # [
2. Any charactter 'except' newline -> . # a, *, -
3. Nongreedy evaluation -> <.*>? # <h1></h2 name = "foo">
4. Whitespace -> s 
 
PREVIOUS NEXT
Tagged: #python #regex
ADD COMMENT
Topic
Name
1+4 =