Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
1import regexLookbehindAvailable from "./utils/regexLookbehindAvailable";
2
3const RESTRICTED_SYMBOLS = "☑️✓✔✅";
4
5// We only want to match a mention when the `@` character is at the start of the
6// line or immediately after whitespace.
7const MATCH_BEHIND = regexLookbehindAvailable ? "(?<=^|\\s)" : "";
8
9const MENTION_NAMESPACE = "\\w+\\/";
10const MENTION_BODY = "([\\dA-Za-z]\\w{1,25})";
11const EDITOR_MENTION = "([\\dA-Za-z]\\w*)"; // This will start searching for mentions after the first character
12
13export const Regex = {
14 // Match string like @someone.
15 accountNameFilter: new RegExp(`[${RESTRICTED_SYMBOLS}]`, "gu"),
16 accountNameValidator: new RegExp(`^[^${RESTRICTED_SYMBOLS}]+$`),
17 evmAddress: /^(0x)?[\da-f]{40}$/i,
18 // Match string like @lens/someone.
19 mention: new RegExp(
20 `${MATCH_BEHIND}@${MENTION_NAMESPACE}${MENTION_BODY}`,
21 "g"
22 ),
23 // modified version of https://stackoverflow.com/a/6041965/961254 to support unicode international characters
24 url: /\b(http|https):\/\/([\p{L}\p{N}_-]+(?:(?:\.[\p{L}\p{N}_-]+)+))([\p{L}\p{N}_.,@?^=%&:/~+#-]*[\p{L}\p{N}_@?^=%&/~+#-])/gu,
25 username: /^[\dA-Za-z]\w{1,25}$/g
26};
27
28export const EditorRegex = {
29 emoji: new RegExp(`${MATCH_BEHIND}:\\w*$`, "g"),
30 mention: new RegExp(`${MATCH_BEHIND}@${EDITOR_MENTION}$`, "g")
31};