Regular Expressions in BAS
The Regular Expressions module in Browser Automation Studio — match, extract, replace and group text with patterns when plain string operations are not flexible enough.
When the text you need follows a shape rather than sitting at a fixed spot — every email, every price, every confirmation code on a page — you reach for regular expressions. The regex module is BAS’s flexible pattern matcher, a step up from plain string operations.
What it’s for
You write a pattern that describes the text you’re looking for, and the module finds, extracts or replaces whatever matches it. It’s used to search and replace strings within text or files, and the strength is flexibility: one pattern can match many variations. BAS works easily with regex and can extract data from strings, replace it, or group it.
The actions
- First occurrence — return the first match of the pattern.
- Extract all data — return every match at once, ideal for pulling a whole set of items (all the emails or links in a blob of text).
- Does the string match the regex — test whether a string fits a pattern. This is how you validate input — is this actually an email, a phone number, a valid code?
- Replace string — substitute text by pattern, cleaning or reformatting in one pass.
String ops vs regex
The rule of thumb: use string operations for fixed text — a known substring, a known position. Reach for regex when the target is a pattern — variable but structured. Need the price out of “Now only $1,299.00!”? That’s a regex job. Need everything after a fixed marker? A string op is enough.
Regex is also the natural finisher for parsing: pull a chunk out of a page with XPath, then use a pattern to extract the exact value buried inside it. Learn a handful of common patterns — email, phone, number, URL — and you’ll cover most of what real bots need.
FAQ
When should I use regular expressions instead of string operations in BAS?
Use regex when the text you want follows a pattern rather than a fixed shape — emails, phone numbers, codes, prices. String operations handle fixed substrings; regex handles flexible patterns and can extract or replace all matches at once.
What can the regex module do in BAS?
It can return the first match, extract all matches, test whether a string matches a pattern, and replace text by pattern. BAS works easily with regex and can extract, replace or group data from strings.
- Browser Automation Studio: The Complete Practical GuideGuide
- Building Your First Bot in Browser Automation StudioA step-by-step walkthrough of creating your first working BAS bot — from a blank project to a flow that navigates, extracts data, and runs in multiple threads.
- Setting Up Proxies in Browser Automation StudioHow to configure proxies in BAS the right way — proxy types, per-thread assignment, rotation, and the checks that keep multi-account bots from getting flagged.
- Finding Elements in BAS: Selectors That Don't BreakHow element search works in Browser Automation Studio — CSS vs XPath selectors, why recorded ones break, and how to write selectors that survive page changes.