Regex
ZK Email allows you to create zero-knowledge proofs of emails. You can define a decomposed regex to extract specific fields from an email (such as sender, recipient, subject, timestamps, etc.) while keeping the rest of the email private.
This page will explain how regex works, how decomposed regex is used in ZK Email, common special characters, and provide template examples for popular email fields.
What is Regex?
Regex (short for regular expression) is a sequence of characters that forms a search pattern. It is widely used to match or find strings in text. For example, you might use regex to find all email addresses in a long document, or to validate if a user’s input meets certain rules (e.g., format of a phone number).
A regular expression uses a combination of:
- Literal characters (e.g., letters, numbers, punctuation).
- Metacharacters (e.g.,
^
,$
,(
,)
,?
,+
,*
,[
,]
,{
,}
,|
,\
). - Quantifiers (e.g.,
?
,+
,*
,{m,n}
). - Character classes (e.g.,
[A-Za-z0-9]
,[^a-z]
,\s
). - Anchors (e.g.,
^
for start of string,$
for end of string,\b
for word boundary).
These building blocks allow you to define very patterns to search or extract substrings from text.
Examples:
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}
- Matches email addresses. Try out.^(\([0-9]{3}\) |[0-9]{3}-)[0-9]{3}-[0-9]{4}$
- Matches US phone numbers. Try out.^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}$
- Matches valid IP address octets (0-255). Try out.