My QA Projects

QA Projects I was involded.

View on GitHub

Regular Expressions

Learning Objectives

What are Regular Expressions?

Regular Expressions Advantages

String Examples With Patterns

The Regular Expression Module

Using the Regex Module

import the re module => call search methods with regular expression pattern and string => Match object is returned

Search Method Method

Search Method

re.search(pattern, string)

# return a match object if a regex pattern is found in string 
# return None if not found

Match Method

re.match(pattern, string)

# return a match object if a regex pattern is found at the beginning of string 
# return None if not found

Find All All Method

re.findall(pattern, string)

# return a list of all substrings in string that matches the regex pattern 
# return empty list if nothing is found

Search Example

import re
pattern= 'ware'
s = 'software hardware'
 if re.search(pattern, s):
    print('matched')

Match Object

Match Object Example

import re
pattern= 'ware'
s = 'software hardware'
mo = re.search(pattern, s)
 if mo:
    print(mo.group())
    # Output ware