CampbeMG
Embedded Systems Breaker
LEVEL 1
500 XP
Hi everyone, today I would like to help u out with some pretty simple regex to make configs or capture that works with many sites because of the often similar scenarios.
This is not really a regex tutorial (if u want to create something more complex, this is definitely not the tutorial for u).
Before this starts, I would really recommend u to use https://regexr.com/ to create a regex!
So we have an HTML string (from a website where we wanna capture the username of the account, for example):
Alright so let's do the regex to get "PleaseMatchMe".
At first, we wanna get the string which contains our username. So the regex would be:
So this would give us as output:
As u may have noticed the string doesn't look very different to the regex. Only in front of the slash was placed a backslash to escape it.
But that's not what we want because we only want to get the username. So what we will do is create a group which contains our string "PleaseMatchMe".
We can create a group by putting our text in brackets:
If we output this groups value this is what happens (on regexr this can be done by hovering over the matched string):
PleaseMatchMe
Nice. But obviously, this wouldn't work, if the username is "OtherMatchMe". So we modify our regex the last time:
This regex would match any Username.
The "." matches any character.
The "*" matches all preceding token.
For example, we only want to capture usernames which contain only "a"s the regex would look like:
This would match "aaaa" or "aa" but not "aab".
This tutorial is very simple but can be used on many sites.
Hope I was able to help u out a bit
This is not really a regex tutorial (if u want to create something more complex, this is definitely not the tutorial for u).
Before this starts, I would really recommend u to use https://regexr.com/ to create a regex!
So we have an HTML string (from a website where we wanna capture the username of the account, for example):
Code:
<whatever>
Your Username:
Your Coins:
</whatever>
At first, we wanna get the string which contains our username. So the regex would be:
Code:
Your Username:
Code:
Your Username: PleaseMatchMe
But that's not what we want because we only want to get the username. So what we will do is create a group which contains our string "PleaseMatchMe".
We can create a group by putting our text in brackets:
Code:
Your Username: (PleaseMatchMe)<\/a>
PleaseMatchMe
Nice. But obviously, this wouldn't work, if the username is "OtherMatchMe". So we modify our regex the last time:
Code:
Your Username: (.*)<\/a>
The "." matches any character.
The "*" matches all preceding token.
For example, we only want to capture usernames which contain only "a"s the regex would look like:
Code:
Your Username: (a*)<\/a>
This tutorial is very simple but can be used on many sites.
Hope I was able to help u out a bit