Quantcast
Channel: User mikyll98 - Stack Overflow
Viewing all articles
Browse latest Browse all 102

How to check if a regex string is PCRE-compliant?

$
0
0

In Lua, is there a way to check if a string is a valid PCRE pattern?

Examples:

local function is_valid_regex(pattern)  -- Check if the pattern is PCRE-compliantend-- Testprint(is_valid_regex(".*"))       -- trueprint(is_valid_regex("[a-z]+"))   -- trueprint(is_valid_regex("([0-9]"))   -- false (unbalanced parentheses)print(is_valid_regex("*invalid")) -- false (invalid usage of *)

Viewing all articles
Browse latest Browse all 102

Trending Articles