Regular Expression

A RegEx, or Regular Expression, is a sequence of characters that forms a search pattern. RegEx can be used to check if a string contains the specified search pattern.

 · 1 min read

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)

FunctionDescription
findallReturns a list containing all matches
searchReturns a Match object if there is a match anywhere in the string
splitReturns a list where the string has been split at each match
subReplaces one or many matches with a string




Satyendra Kumar

Today i learn intro

No comments yet.

Add a comment
Ctrl+Enter to add comment