PythonRegEx
RegEx Module
Python has a built-in package calledre
, which can be used to work with Regular Expressions.
Import there
module:
import re
RegEx in Python
When you have imported there
module, you can start using regular expressions:
Example
Search the string to see if it starts with "The" and ends with "Spain":
import re
txt = "The rain in Spain"
x = re.search("^The.*Spain$", txt)
Try it Yourself »txt = "The rain in Spain"
x = re.search("^The.*Spain$", txt)
Related Pages
Python RegEx TutorialRegEx FunctionsMetacharacters in RegExRegEx Special SequencesRegEx SetsRegEx Match Object