fix: update regex

This commit is contained in:
codytseng
2025-08-30 22:23:51 +08:00
parent 13527a3ca7
commit cbac9c5464
2 changed files with 8 additions and 10 deletions

View File

@@ -95,13 +95,9 @@ export const SUPPORTED_KINDS = [
]
export const URL_REGEX =
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+(?<![.,;:'")\]}!?""''])/gu
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+(?=[^.,;:'")\]}!?"']|$)/gu
export const WS_URL_REGEX =
/wss?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+(?<![.,;:'")\]}!?""''])/gu
export const IMAGE_REGEX =
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-]+\/(?:[^/\s?]*\/)*([^/\s?]*\.(jpg|jpeg|png|gif|webp|bmp|tiff|heic|svg|avif))(?!\w)(?:\?[\w\p{L}\p{N}\p{M}&=.-]*)?(?<![.,;:'")\]}!?""''])/giu
export const MEDIA_REGEX =
/https?:\/\/[\w\p{L}\p{N}\p{M}&.-]+\/(?:[^/\s?]*\/)*([^/\s?]*\.(mp4|webm|ogg|mov|mp3|wav|flac|aac|m4a|opus|wma))(?!\w)(?:\?[\w\p{L}\p{N}\p{M}&=.-]*)?(?<![.,;:'")\]}!?""''])/giu
/wss?:\/\/[\w\p{L}\p{N}\p{M}&.-/?=#\-@%+_:!~*]+(?=[^.,;:'")\]}!?"']|$)/gu
export const EMAIL_REGEX = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/
export const EMOJI_SHORT_CODE_REGEX = /:[a-zA-Z0-9_-]+:/g
export const EMBEDDED_EVENT_REGEX = /nostr:(note1[a-z0-9]{58}|nevent1[a-z0-9]+|naddr1[a-z0-9]+)/g

View File

@@ -5,13 +5,15 @@ import { nip19 } from 'nostr-tools'
export function parseEditorJsonToText(node?: JSONContent) {
const text = _parseEditorJsonToText(node).trim()
const regex = /(?<=^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g
const regex = /(?:^|\s)(nevent|naddr|nprofile|npub)[a-zA-Z0-9]+/g
return text.replace(regex, (match) => {
const _match = match.trim()
try {
nip19.decode(match)
return `nostr:${match}`
nip19.decode(_match)
return `nostr:${_match}`
} catch {
return match
return _match
}
})
}