Skip to main content
Back to blog
tools 28 April 2020 2 min read

Data Extraction

A collection of useful regular expressions for data extraction and validation in testing environments, covering emails, dates, passwords, and more.

M

Mark

Performance Testing Expert

Data extraction methods are essential for testing environments. Regular expressions provide a powerful targeting tool for validating and extracting specific data patterns.

Common Regular Expression Patterns

Email Validation

Ensures valid characters before the @ symbol and proper domain structure:

^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

UK National Insurance Number (NINO)

Targets UK National Insurance Numbers in the format QQ123456C:

^[A-CEGHJ-PR-TW-Z]{2}[0-9]{6}[A-D]$

Whitespace Trimming

Removes leading and trailing spaces from lines:

^\s+|\s+$

Strong Password Validation

Requires lowercase, uppercase, numbers, special characters, and a minimum of 8 characters:

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Date Format (YYYY-MM-DD)

Validates date structure:

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$

Username Validation

Allows underscores and hyphens, 3-16 character length:

^[a-zA-Z0-9_-]{3,16}$

IPv4 Address

Validates IPv4 address format:

^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

IPv6 Address

Validates IPv6 addresses in formats like 2001:cdba:0000:0000:0000:0000:3257:9652:

^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$

Time Format (12-hour)

Validates time in HH:MM format:

^(0?[1-9]|1[0-2]):[0-5][0-9]$

Time Format (24-hour)

Validates time in HH:MM:SS format:

^([01]?[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$

International Phone Numbers

Supports country codes and extensions:

^\+?[1-9]\d{1,14}$

Using Regular Expressions

Regular expressions can be used in various contexts:

  • JMeter - Regular Expression Extractor and Boundary Extractor
  • Programming languages - Python, Java, JavaScript all have regex support
  • Text editors - VS Code, Sublime Text, and others support regex search
  • Command line - grep, sed, and awk utilities

Testing Your Patterns

Before using regex patterns in production tests, validate them using online tools:

  1. Create test cases for both valid and invalid inputs
  2. Test edge cases specific to your data
  3. Consider performance for large datasets

Further Reading

Tags:

#regex #regular-expressions #data-extraction #validation #testing

The cheat sheets, as printable PDFs

All 52 are free to read on the site — no signup. Want them as A4 PDFs you can actually print? The pack covers JMeter, k6, Gatling, Docker, Kubernetes and observability, and costs nothing but an email address.

Get the PDF pack

Delivered by email. Unsubscribe any time — see our privacy policy.

Stuck on this in your own test suite?

I take on fixed-price, fixed-turnaround performance work — script migrations, HAR-to-script conversion and written performance audits. No calls required.

Get in Touch