Thematch () method searches for a regular expression at the beginning of a string. If the optional parameter pos is supplied, the search starts at position pos, which is consider! d the start. If the optional parameter endpos is supplied, the search ends when endpos is encountered. The default is from position 0 to the end of the string. The return Is a match object.
Here's an example that aoesn'n mftchbecause the tesI isn't at the beginning of the stting. Therefore, noahing is printed out.
>>> if (cre.match("This is a test")): ... print "From beginning \n"
Here's an example in which the starting position is 10. A match is returned only if the expression is found at the beginning of the string.
>>> if (cre.match("This is a test",10)): . .. print "From pos 10 - \n"
Was this article helpful?