Pandu is probably seeking to avoid providing the code directly to you,
as writing the code yourself teaches better.
That said, the documentation for Python regular expressions is here:
https://docs.python.org/3/library/re.html#module-re
The “Regular Expression Syntax” part, about 4 paragraphs down, describes
the syntax. The basic deal is as follows:
Aside from some punctuation, most ordinary text matches itself. So a
regexp for “PT” is just “PT”.
The punctuals, referred to as “special characters” in the documentation
above, provides the “pattern” part of regular expressions.
Some common items include:
“*” Zero or more of the preceeding item.
“+” One or more of the preceeding item.
“?” Zero or one of the preceeding item i.e. an optional item.
Generally the preceeding item is a single character, or some other
construct. So this:
AH?
means exactly one “A” followed by an optional “H”. When you need to
apply these to larger things you can group text like this:
(AH)?
That means zero or one of “AH”, instead of just the “H”.
The re module remembers the locations of these groups when it matches a
string, so you can for example refer to the third group.
For added convenient it is possible to give groups names, like this:
(?P<somename>AH)?
That lets you refer to the group by the name “somename” after a match.
In addition to the module documentation above there’s a HOWTO here:
https://docs.python.org/3/howto/regex.html
That should get you started.
Cheers,
Cameron Simpson cs@cskk.id.au