Regular expressions

Online Courses

Regular Expressions
Regular Expressions may be used to test if a string (Text) is according to a certain grammar. Sometimes Regular Expressions are called regex or regexp.  We can easily test if a string contains another string:

You can also test if a string does not contain a substring:

We may define a grammar, to match against any input string. Let’s say we want to match against three digits, we would define a gramamr ‘\d{3}\Z’. Example:

This will out put “True” if the string s matches the grammar string.

Grammar rules
The permitted grammar for regular expressions is:

Previous Post
Next Post


  • Omar says:

    What does the \Z do in matcher = re.match(‘\d{3}\Z’,s)

    • CodeNinja says:

      It matches the end of string. If a newline exists, it matches before newline.

Leave a Reply