
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
re2shield
Advanced tools
A Python library that provides a convenient interface for compiling and matching regular expression patterns using the re2 library.
re2shield is a Python library that provides a shield for working with regular expressions using the re2 module.
It allows you to compile and search for patterns in text using the powerful regular expression engine provided by re2.
It allows you to hide the complexity of regular expressions and work with pattern identifiers instead.
This project utilizes the google/re2 library, which is licensed under the BSD 3-Clause License. Please refer to the LICENSE file of google/re2 for more information.
Before installing re2shield, make sure that re2 is installed on your system. You can install re2 by following the instructions on the google/re2 GitHub repository.
Alternatively, you can use the re2-installer.sh script located in the package/installed directory. This script automates the installation process for re2 and its dependencies. Simply run the script using the following command:
git clone https://github.com/Npc-coder/re2shield.git
cd re2shield/installed
sh re2-installer.sh
You can install re2shield using pip:
pip install re2shield
or
git clone https://github.com/Npc-coder/re2shield.git
cd re2shield
pip install .
Please refer to the Usage section for examples of how to use these new features.
Here is a simple example demonstrating how to use re2shield:
import re2shield
if __name__ == "__main__":
db = re2shield.Database(version='1.0.0')
# Load patterns from file
try:
db = re2shield.load('patterns.db')
except FileNotFoundError:
# If pattern file doesn't exist, compile the patterns
patterns = [
(r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b', 1),
(r'\b\d{3}[-.\s]??\d{3}[-.\s]??\d{4}\b', 2),
(r'\d+', 3)
]
expressions, ids = zip(*patterns)
db.compile(expressions=expressions, ids=ids, overwrite=False)
db.dump('patterns.db')
# Find patterns in text
def match_handler(id, from_, to, context):
print(f"Match found for pattern {id} from {from_} to {to}: {context}")
db.scan('test@ex12ample12.com', match_handler)
In this example, we create a re2shield.Database object, compile a list of patterns with their corresponding identifiers, and then search for those patterns in the provided text.
The match_handler function is called for each match found, allowing you to process the matches as desired.
One of the key advantages of re2shield is its ability to hide the actual regular expression patterns from users during distribution. By compiling the patterns with re2 and using pattern identifiers, you can distribute your code without exposing the underlying regular expression logic. This provides an additional layer of abstraction and enhances the security of your regular expression patterns.
This project is licensed under the BSD 3-Clause License. See the LICENSE file for details.
FAQs
A Python library that provides a convenient interface for compiling and matching regular expression patterns using the re2 library.
We found that re2shield demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.