September 13, 2026
Regex for Hackers: Using Regex for Recon & Broken Validation
In this blog, I wonβt teach you how to write regular expressions from scratch. There are already plenty of great tutorials and resourcesβ¦

By default
4 min read
In this blog, I won't teach you how to write regular expressions from scratch. There are already plenty of great tutorials and resources online for learning regex syntax.βInstead, this blog is about how to use regex as a bug hunter and penetration tester.βWhen you're hunting for vulnerabilities, you often have to deal with a huge amount of data: thousands of URLs, JavaScript files, API responses, parameters, headers, and configuration files. Manually searching through all of this data is slow and inefficient.βRegex can help you turn that huge amount of data into something much more useful.βThis blog will focus on two main areas.
First, I'll talk about how you can use regex to find bugs. In this section, I'll focus on using regex to discover hidden endpoints and hidden assets.β
Then, I'll talk about how to find bugs caused by developers incorrectly implementing regex.
Use Regex to Find Bugs
Githubβ
As you know, GitHub supports regex searches. When I first discovered this, I deleted almost all of the GitHub cheat-sheet keywords I had saved π, because regex allows you to extract exactly what you need from a huge amount of data.βIn this write-up, I will use Facebook as the target.β
For example, if you want to find subdomains under facebook.com, instead of searching for facebook and then manually looking through thousands of results for subdomains, you can use a simple regex to extract exactly what you need.β
This regex can help you find subdomains and endpoints under Facebook domains:ββ
/https?:\/\/[a-z0β9\.-]+\.facebook\.com\/([a-z0β9-_]+\/)*v[0β9]+\/β/https?:\/\/[a-z0β9\.-]+\.facebook\.com\/([a-z0β9-_]+\/)*v[0β9]+\/βWhen you combine a regex with a normal GitHub search operator, you can make the search much more powerful. For example:β
/https?:\/\/[a-z0β9\.-]+\.facebook\.com\/([a-z0β9-_]+\/)*v[0β9]+\/ AND NOT "WWW"β/https?:\/\/[a-z0β9\.-]+\.facebook\.com\/([a-z0β9-_]+\/)*v[0β9]+\/ AND NOT "WWW"βAnother useful regex I use is:
# Find subdomains containing "api"
/https?:\/\/([a-z0-9-]{1,}[\.])*api\.([a-z0-9-]{1,}[\.])*facebook\.[a-z\.]+\//
# Find subdomains that have an API path
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*api\//
# Find Facebook URLs containing /v*/ patterns, such as /api/v1/users
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*v[0-9]+\//
# Find GraphQL endpoints
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*graphql\//
## find all email with password
/[a-zA-Z0-9._%+-]+@target\.com/ AND "password"# Find subdomains containing "api"
/https?:\/\/([a-z0-9-]{1,}[\.])*api\.([a-z0-9-]{1,}[\.])*facebook\.[a-z\.]+\//
# Find subdomains that have an API path
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*api\//
# Find Facebook URLs containing /v*/ patterns, such as /api/v1/users
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*v[0-9]+\//
# Find GraphQL endpoints
/https?:\/\/[a-z0-9\.-]+\.facebook\.[a-z]+\/([a-z0-9-_]+\/)*graphql\//
## find all email with password
/[a-zA-Z0-9._%+-]+@target\.com/ AND "password"β
After understanding the concept, you can start creating your own regex-based GitHub searches for different use cases. With AI tools helping you write and modify regex, creating these searches becomes much easier.β
How I Found a Bug Using This Techniqueβ
During recon, I found a hidden subdomain where I could log in as one of the target's team members.β I went to the Forgot Password section and entered my email address. The application responded:β
_We sent an OTP to your email. Please enter the OTP._β
Because my email was not registered, I didn't receive any OTP.β I tried entering an incorrect OTP. The application returned "Wrong OTP", but when I looked at the response, I noticed:
"status": falseβ"status": falseβI tried changing it to:β
"status": trueβ"status": trueβThe error then changed to **"Email not found."**β
This showed me that response manipulation was possible, but I still needed a valid email address.β I went back to GitHub and searched for email addresses belonging to the target using this regex:β
/[a-zA-Z0β9._%+-]+\@target\.com/ββ/[a-zA-Z0β9._%+-]+\@target\.com/ββI extracted the emails I found and tested them using Burp Intruder with Match and Replace.β One of the email addresses worked, and I was redirected to the dashboard.β
regex with grepβ
As you know, you can use regex with grep using the -E or -P options.β
Here is a simple example of using grep to extract endpoints from JavaScript files. First, download JavaScript files from the target. You can find them by crawling with a tool like katana, or through passive discovery with tools like waymore.β Then:β
cat katana.txt | grep -E "\.js" | fff -S -c 20 ## Download all JS filesββcat katana.txt | grep -E "\.js" | fff -S -c 20 ## Download all JS filesββGrep endpoints
β
gf js-endpoints-without-line |gf blacklist |inscope | sed 's|"||g'ββgf js-endpoints-without-line |gf blacklist |inscope | sed 's|"||g'ββThe gf patterns use grep internally. For example, this is the js-endpoints-without-line pattern:
cat ~/.gf/js-endpoints-without-line.jsonβββ
{
β
"flags": "-ERhoi",
β
"pattern": "(\"|'|`)(https?://[^\"`']+|/[a-zA-Z0β9_?&=/\\#~.:-]+)(\"|'|`)"
β
}βcat ~/.gf/js-endpoints-without-line.jsonβββ
{
β
"flags": "-ERhoi",
β
"pattern": "(\"|'|`)(https?://[^\"`']+|/[a-zA-Z0β9_?&=/\\#~.:-]+)(\"|'|`)"
β
}βAnd this is the blacklist pattern I use to remove common static files:
cat ~/.gf/blacklist.jsonβ
{
β
"flags": "-IEiv",
β
"pattern": "\\.(jpeg|jpg|png|svg|gif|woff|woff2|svg|eot|tif|tiff|ttf|ico|icon|txt|pdf|css|js)$"
β
}βcat ~/.gf/blacklist.jsonβ
{
β
"flags": "-IEiv",
β
"pattern": "\\.(jpeg|jpg|png|svg|gif|woff|woff2|svg|eot|tif|tiff|ttf|ico|icon|txt|pdf|css|js)$"
β
}ββ
Find Regex to Find Bugsβ
Some developers write incorrect regex because the syntax can be tricky. Sometimes, as hackers, we can take advantage of these mistakes to bypass certain security checks.β Some people may think this type of bug will disappear soon because AI can now write regex. But I don't think it will disappear yet.β Sometimes, AI misunderstands what the developer actually needs and generates a regex for the wrong situation. If the developer blindly accepts the generated code, this can still lead to security issues.β
I found this image on one of the blogs I read. I think it really captures what I mean here π
β
βLet's look at a real-world example of how an incorrectly implemented regex can lead to a security vulnerability. For example, consider this code:β
window.addEventListener("message", function(event) {
if (/https:\/\/www\.example\.com/.test(event.origin)) {
if (event.data.type === "error") {
div.innerHTML(event.data.error.message);
}
}
});ββwindow.addEventListener("message", function(event) {
if (/https:\/\/www\.example\.com/.test(event.origin)) {
if (event.data.type === "error") {
div.innerHTML(event.data.error.message);
}
}
});ββThe developer is trying to allow messages only from https://www.example.com, but the regex is not anchored.β An attacker can register a domain such as:β
https://www.example.com.attacker.comββhttps://www.example.com.attacker.comββand host an HTML payload there.β Because the regex only checks whether https://www.example.com appears in the origin, the attacker's domain can pass the check.
Since the application also places event.data.error.message directly into innerHTML, this can potentially lead to XSS.
β