Regular expression sets in Python
The regular expression sets used to define a set of characters inside a pair of square brackets []. It allows to specify a selected characters, range that determine selected or range of characters are present in the source value.

Characters set

If a characters set specified as regular expression, it determine whether one of the specified characters is present in the source string.
Characters set
 1 # import regular expression module
 2 import re
 3 
 4 string = "Hello world !"
 5 found = re.findall("[ewa]", string)
 6 
 7 if found:
 8   print("Match found in string ")
 9 else:
 10   print("Match does not found !")
 11 
 12 # Output
 13 # Match found in string
Note : It can be any characters uppercase, lowercase letter, number symbol etc

Range set

If a range characters set specified as regular expression, it determine whether one of the specified characters specified in range is present in source string.
Range set
 1 # import regular expression module
 2 import re
 3 
 4 string = "Hello world !"
 5 # it match for any lower case letter between a and z
 6 found = re.findall("[a-z]", string)
 7 
 8 if found:
 9   print("Match found in string ")
 10 else:
 11   print("Match does not found !")
Note : It can be any range that can be uppercase [A-Z], lowercase [a-z], number [0-9]

Negate set

A negate set allows to specify that the specified characters or range should not include in the source string.
Negate set
 1 # import regular expression module
 2 import re
 3 
 4 string = "hello world"
 5 
 6 # it validate any character present except ewd
 7 f1 = re.findall("[^ewd]", string)
 8 f2 = re.findall("[^a-z ]", string) # a-z and space
 9 
 10 if f1:
 11   print("Match found in string ")
 12 else:
 13   print("Match does not found !")
 14   
 15 if f2:
 16   print("Match found in string ")
 17 else:
 18   print("Match does not found !")
Output
 1 Match found in string
 2 Match does not found !

Other sets example

Other sets example
 1 [ewd]:	It specifies whether one of the specified characters (e, w, or d) is present	
 2 [a-k]:	It specifies whether any lower case character between a and k is present
 3 [^ewd]:	It specifies whether any character EXCEPT e, w, and d	
 4 [012]:	It specifies whether any of the specified digits (0, 1, or 2) are present	
 5 [0-9]:	It specifies whether any digit between 0 and 9	
 6 [0-5][0-9]:  It specifies whether any two-digit numbers from 00 and 59	
 7 [a-zA-Z]:  It specifies whether any character alphabetically between a and z, lower case OR upper case	
 8 [symbol|operator| etc]:	It specified, it does not have special meaning, hence, it determine any + character in the string
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us