

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we use Python regular expression to match a date string?
In the first case in the code below the given date string matches the d-m-y format and in the second case the date string does not match the format
Example
import re datestring = '21-09-1991' foo =re.match('(\d{2})[/.-](\d{2})[/.-](\d{4})$', datestring) print foo.group() datestring = '1991-09-21' foo =re.match('(\d{2})[/.-](\d{2})[/.-](\d{4})$', datestring) print foo
Output
21-09-1991 None
- Related Questions & Answers
- How do we use a delimiter to split string in Python regular expression?
- How do we use Python Regular Expression named groups?
- How do we use re.finditer() method in Python regular expression?
- How to match a regular expression against a string?
- Why do we use re.compile() method in Python regular expression?
- How do we find the exact positions of each match in Python regular expression?
- Why do we use question mark literal in Python regular expression?
- How to match parentheses in Python regular expression?
- How to use regular expression in Java to pattern match?
- How to query an Array[String] for a Regular Expression match?
- How to match a word in python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match a single character in python using Regular Expression?
- How to match a nonwhitespace character in python using Regular Expression?
- How to match at the beginning of string in python using Regular Expression?
Advertisements