Posts

Showing posts with the label Regular Expression

Introduction to regular expressions in Python (2020 tutorial)

Image
  1. Introduction to RegEx You have been surfing on the web for a long time and sometimes you need to sign up with your email address for some services from a website. Every website will validate your email address first and if you have entered an invalid one, you will be rejected to register. Here is the question, how come the web service validate the email address you just entered? The answer is regular expression. The web service will use a regular expression pattern to match against your email address; if match, you are allowed to register otherwise you will be rejected. if "foo@google.com" match "pattern":     allow_register() else:     deny_register( ) Actually regular expression is a tiny programming language embedded with python. You could use this tiny programming language through its re module. So let's dive in. 2. A simple match >>> import re >>> re.match(r'hello', 'hello world!') <re.Match object; span=(0, 5), mat...