A regular expression (also called a regex or regexp) is a pattern that can match a piece of text.
The simplest form of regular expression is just a plain string, which matches itself.
A regexp can match more than one string, and you create such a pattern by using some special
characters. For example, the period character (dot) matches any character (except a newline),
so the regular expression '.ython' would match both the string 'python' and the string
'jython'. It would also match strings such as 'qython', '+ython', or ' ython' (in which the first
letter is a single space), but not strings such as 'cpython' or 'ython' because the period matches
a single letter, and neither two nor zero.
and this period is called a wildcard.
(pattern) ? pattern is used to Escaping Special Characters
(pattern)* pattern is repeated zero or more times
(pattern)+ pattern is repeated one or more times
(pattern){m,n} pattern is repeated from m to n times
(pattern) ('^')
pattern is
to mark the beginning
('$')
pattern is
to mark the
So, for example,
'(http://)?(www\.)?
.com'
google
would match all of the following strings (and nothing else):
'http://www.google.com' '
http://google.com'
'www.google.com'
'google.com'
r'w*\
google
'ww.google.com', and 'wwwwwww.google.com'.
Similarly, r'w+\.python\.org' matches
'w.google.com' but not '.google.com',
and r'w{3,4}\.python\.org' matches only
'www.google.com' and 'wwww.google.com'
google.com' (and 'htttttp://
google.com
example:
pattern= r'[.?\-",]+'
pattern=r '[a-zA-Z]+'
pattern=r'\*([^\*]+)\*'
pattern=r'[a-z\-\.]+@[a-z\-\.]+'
Comments
Post a Comment