Data Extraction
Whether inside a test asset or parsing logs in the cloud or server side, knowing methods of targeting and extracting the data you need can be invaluable.
Regular Expressions
One of the most powerful, yet confusing methods of targeting data is the use of regular expressions. Let’s explorer some useful regex that you can use throughout your testing.
Valid Email Address - this will ensure that you have valid characters before the @ symbol and that it has a valid domain.
\b[\w.!#$%&’*+\/=?^`{|}~-]+@[\w-]+(?:\.[\w-]+)*\b
NINO - This finds the National Insurance Number of the format QQ123456C.
^[A-CEGHJ-PR-TW-Z]{1}[A-CEGHJ-NPR-TW-Z]{1}[0-9]{6}[A-D]{0,1}$
Trim spaces - Removes spaces from the beginning or end of lines.
^[\s]*(.*?)[\s]*$
Strong Password - 1 lowercase letter, 1 uppercase letter, 1 number, 1 special character and be at least 8 characters long.
/(?=(.*[0-9]))(?=.*[\!@#$%^&*()\\[\]{}\-_+=~`|:;"'<>,./?])(?=.*[a-z])(?=(.*[A-Z]))(?=(.*)).{8,}/
Date - Checks for YYYY-MM-DD date format.
/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))/
Username - can include _ and – having a length of 3 to 16 character.
/^[a-z0-9_-]{3,16}$/
IPv4 Address - Matches valid IPv4 addresses in format 192.168.1.1
/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/
IPv6 Address - Matches valid IPv6 addresses in format 2001:cdba:0000:0000:0000:0000:3257:9652
/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/
Time - HH-MM 12 Hour optional leading 0
/^(0?[1-9]|1[0-2]):[0-5][0-9]$/
Time - HH-MM-SS 24 Hour
/(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)/
Phone numbers (International) - with option country code/extension
/^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$/