The regular expression would match any other characters than t, i, m or e.<\/td>\n<\/tr>\n
\n\n { }<\/p>\n<\/td>\n | The curly brackets accept two integer values. The first value specifies the minimum number of occurrences and the second value specifies the maximum of occurrences.<\/td>\n | tim{1,4}e<\/p>\n The regular expression would match only strings time, timme, timmme or timmmme.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Regular expression module functions<\/strong><\/p>\nSome of the methods of re module as discussed below:<\/p>\n re. compile ( pattern ) \nThe function compile a regular expression pattern into a regular expression object, which can be used for matching using its match ( ) and search ( ) methods, discussed below.<\/p>\n >>> import re\r\n>>> p=re.compile ( ' tim*e ' )<\/pre>\nre. match ( pattern, string ) \nIf zero or more characters at the beginning of the string match the regular expression pattern, match-( ) return a corresponding match object instance. The function returns None if the string does not match the pattern.<\/p>\n re. group ( ) \nThe function return the string matched by the RE.<\/p>\n >>> m=re .match ( ' tim*e' , ' timme pass time ' )\r\n>>> m. group ( )\r\n' timme '<\/pre>\nThe above patch of code can also be written as:<\/p>\n >>> p=re. compile ( ' tim*e ' )\r\n>>> m=p.match ( ' timme pass timme ' )\r\n>>> m.group ( )\r\n'timme'<\/pre>\nre. search ( pattern, string ) \nThe function scans through string looking for a location where the regular expression pattern produces a match, and returns a corresponding match object instance. The function returns None if no position in the string matches the pattern.<\/p>\n >>> m=re.search( ' tim*e ' ' no passtimmmeee ' )\r\n>>> m.group ( )\r\n' timmme '<\/pre>\nThe above patch of code can also be written as:<\/p>\n >>> p=re.compile ( ' tim*e ' )\r\n>>> m=p.search ( ' no passtimmmeee ' )\r\n>>> m.group ( )\r\n' timmme '<\/pre>\nre.start ( ) \nThe function returns the starting position of the match.<\/p>\n re.end ( ) \nThe function returns the end position of the match.<\/p>\n re.span ( ) \nThe function returns a tuple containing the ( start, end ) indexes of the match.<\/p>\n >>> m=re.search ( ' tim*eno passtimmmeee ' )\r\n>>> m.start ( )\r\n7\r\n>>> m.end ( )\r\n13\r\n>>> m.span ( )\r\n( 7 , 13 )<\/pre>\nThe above patch of code can also be written as:<\/p>\n >>> p=re.compile ( ' tim*e ' )\r\n>>> m=p.search ( ' no passtimmmeee ' )\r\n>>> m.start ( )\r\n7 \r\n>>> m.end ( )\r\n13\r\n>>> m.span ( )\r\n( 7 , 13 )<\/pre>\nre. findall ( pattern, string ) \nThe function returns all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returned in the order found.<\/p>\n >>> m=re.findall ( ' tim*e ' , ' timeee break no pass timmmeee ' )\r\n>>> m \r\n[ ' time ' , ' timmme ' ]<\/pre>\nThe above patch of code can also be written as:<\/p>\n >>> p=re . compile ( ' tim*e ' )\r\n>>> m=p.findall ( ' timeee break no pass timmmeee ' )\r\n>>> m\r\n[ ' time ', ' timmme ' ]<\/pre>\nre. finditer ( pattern, string ) \nThe function returns an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in a string. The string is scanned left-to-right, and matches are returned in the order found.<\/p>\n >>> m=re.finditer ( ' tim*e ', ' timeee break no pass timmmeee ' )\r\n>>> for match in m :\r\n. . .\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0print match.group ( )\r\n. . .\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0print match.span ( )\r\ntime \r\n( 0 , 4 ) \r\ntimmme \r\n( 21 , 27 )<\/pre>\nThe above patch of code can also be written as:<\/p>\n >>> p=re.compile( ' tim*e ' )\r\n>>> m=p.finditer ( ' timeee break no pass timmmeee ' )\r\n>>> for match in m :\r\n. . . print match.group ( )\r\n. . . print match.span ( )\r\ntime \r\n( 0 , 4 ) \r\ntimmme\r\n( 21 , 27 )<\/pre>\n","protected":false},"excerpt":{"rendered":"In this Page, We are Providing Basics of Python \u2013 Regular Expression Module. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Basics of Python \u2013 Regular Expression Module Regular expression module A regular expression (also called RE, or regex, or regex pattern) is a specialized approach in Python, using which programmers …<\/p>\n Basics of Python \u2013 Regular Expression Module<\/span> Read More »<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"yoast_head":"\nBasics of Python \u2013 Regular Expression Module - Python Programs<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n |