- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain Python regular expression search vs match
Both re.match() and re.search() are methods of the Python module re.
The re.match() method finds match if it occurs at start of the string. For example, calling match() on the string ‘TP Tutorials Point TP’ and looking for a pattern ‘TP’ will match.
result = re.match(r'TP', 'TP Tutorials Point TP') print result.group(0)
The re.search() method is similar to re.match() but it doesn’t limit us to find matches at the beginning of the string only.
result = re.search(r'Tutorials', 'TP Tutorials Point TP') print result.group(0)
Here you can see that, search() method is able to find a pattern from any position of the string.
- How to match parentheses in Python regular expression?
- Lua pattern matching vs regular expression
- PHP – Match regular expression using mb_ereg_match()
- How to match a word in python using Regular Expression?
- How to match nonword characters in Python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- Explain C# Quantifiers in regular expression
- Explain C# Substitution in regular expression
- Explain the concept of Regular expression.
- MongoDB regular expression to match a specific record?
- Text search in MongoDB with Regular Expression
- How to match a nonwhitespace character in python using Regular Expression?
- How to match only non-digits in Python using Regular Expression?