One day I want to meet a regular expression expert.
Flags often follow a specific pattern. For example, if flags are in the format FLAG{...}
, you can use:
grep -o 'FLAG{[^}]*}' filename
This will match any text that starts with FLAG{
and ends with }
Use case:
Base64 encoded strings typically end with =
or ==
. You can use:
grep -Eo '[A-Za-z0-9+/]{4,}={0,2}' filename
This matches sequences of characters that are likely Base64 encoded.
To find IP addresses in a file, use:
grep -Eo '([0-9]{1,3}\\.){3}[0-9]{1,3}' filename
This matches patterns that look like IPv4 addresses.
To find email addresses, use:
grep -Eo '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}' filename
This matches common email address formats.