Regular Expressions 101

Community Patterns

Your search did not match anything

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(?'start'\{\n)|((?'line' (?U)(".*")\: (".*")(?-U),?\n))|(?'end'\})
/
gm

Description

Converts a JSON-like object of "key": "value" pairs into a SQL CASE statement using a single regex replace with named conditional groups.

✅ Works in PCRE2 flavor only. 🚫 Will not work in JavaScript, Python <3.12, or other engines without conditional replacements.

Submitted by Moron - 2 months ago