/regxy

Python module for making regex painless.

Primary LanguagePython

regxy

Python module for making regex painless.

Operations Supported

  • Match everything between two texts
  • Extract emails
  • Extract phone numbers

Installation

You can install it using pip as follows:

pip install regxy

or you can clone this repo for favoring portability:

git clone https://github.com/UltimateHackers/rexgy/

Usages

grab

Lets say there's website which generates a random password when you visit it. By looking at the source code, you find this:

This is your random password: <span color="red" id="pass">puSSySlay3r</span>. Enjoy!

Now you want to write a program which can visit the website can and can return you the generated password. In that case, you can use regxy as follows:

from regxy import grab
password = grab(string, 'id="pass">', '</span>')
print password

Output

puSSySlay3r

The syntax is following:

grab(string, start, end)

Where string is the string you want to process, start and end are the texts within which your infromation of interest lies.
In this case your string is the source code of the website which can be extracted by other modules.

graball

Lets say there's a website which has a list of proxies and you want to write a program to extract those proxies. The source code is something like:

<td class="dark">127.0.0.1:80</td>
<td class="dark">127.0.0.2:8080</td>
<td class="dark">127.0.7:80</td>
<td class="dark">127.255.255.255:80</td>

In this case, you can use the graball function which returns all the matches unlike grab which only returns one. The syntax is as same as the grab function but it returns a list and not a string.

from regxy import graball

grab(string, 'pass">', '</td>')

emails

As the name suggest, this function can extract emails from a given string with 99.99% accuracy. Usages:

from regxy import emails
emails(string)

It returns a list of matches.

numbers

This function can extract phone numbers from a given string. Usages:

from regxy import numbers
numbers(string)

It returns a list of matches.

What if there's no match?

Well in that case all the functions return False.

Cheat Sheet

Function Syntax Output
grab grab(string, start, end) string
graball grab(string, start, end) list
emails emails(string) list
numbers numbers(string) list

License & Contribution

Contributions are heartly welcome, doesn't matter if they are bug reports, pull requests or ideas to make regxy better.

Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.