बैकरेफ़रेंसेज़

Python में Regular Expressions

Maria Eugenia Inzaugarat

Data Scientist

नंबर वाली ग्रुप्स

 

 

Python में Regular Expressions

नंबर वाली ग्रुप्स

 

Python में Regular Expressions

नंबर वाली ग्रुप्स

 

text = "Python 3.0 was released on 12-03-2008."
information = re.search(r'(\d{1,2})-(\d{2})-(\d{4})', text)

information.group(3)
'2008'
information.group(0)
'12-03-2008'
Python में Regular Expressions

नेम्ड ग्रुप्स

  • ग्रुप्स को एक नाम दें

 

Python में Regular Expressions

नेम्ड ग्रुप्स

  • ग्रुप्स को एक नाम दें
text = "Austin, 78701"

cities = re.search(r"(?P<city>[A-Za-z]+).*?(?P<zipcode>\d{5})", text)
cities.group("city")
'Austin'
cities.group("zipcode")
'78701'
Python में Regular Expressions

बैकरेफ़रेंसेज़

  • कैप्चरिंग ग्रुप्स से पहले वाले ग्रुप को संदर्भित करें

 

Python में Regular Expressions

बैकरेफ़रेंसेज़

  • नंबर वाली कैप्चरिंग ग्रुप्स से संदर्भित करें

 

sentence = "I wish you a happy happy birthday!"

re.findall(r"(\w+)\s ", sentence)
Python में Regular Expressions

বैकरेफ़रेंसेज़

  • नंबर वाली कैप्चरिंग ग्रुप्स से संदर्भित करें

 

sentence = "I wish you a happy happy birthday!"

re.findall(r"(\w+)\s\1", sentence)
['happy']
Python में Regular Expressions

बैकरेफ़रेंसेज़

  • नंबर वाली कैप्चरिंग ग्रुप्स से संदर्भित करें

 

sentence = "I wish you a happy happy birthday!"

re.sub(r"(\w+)\s\1", r"\1", sentence)
'I wish you a happy birthday!'
Python में Regular Expressions

बैकरेफ़रेंसेज़

  • नेम्ड कैप्चरिंग ग्रुप्स से संदर्भित करें

 

sentence = "Your new code number is 23434. Please, enter 23434 to open the door."

re.findall(r"(?P<code>\d{5}).*?(?P=code)", sentence)
['23434']
Python में Regular Expressions

बैकरेफ़रेंसेज़

  • नेम्ड कैप्चरिंग ग्रुप्स से संदर्भित करें

 

sentence = "This app is not working! It's repeating the last word word."
re.sub(r"(?P<word>\w+)\s(?P=word)", r"\g<word>", sentence)
'This app is not working! It's repeating the last word.'
Python में Regular Expressions

अभ्यास करते हैं!

Python में Regular Expressions

Preparing Video For Download...