Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

/
^(?(DEFINE)(?'word'(?:[a-zA-Z0-9!?'"&\.,+@%~$]|(?<! )-(?! ))+)(?'words'(?&word)(?: (?&word))*?)(?'nothe'(?<!, (?i:a))(?<!, (?i:the|les)))(?'ver_prefix'Rev|Proto|Alpha|Beta))(?'title'(?&words)(?&nothe))(?'subtitle' - (?&words))*?(?'upd' (?:Update|DLC - (?&words)))?(?'region' \((?:(?:A|As|B|C|Ch|Nl|E|F|G|Gr|Hk|I|J|K|No|R|S|Sw|U|Uk|Tw|W))+\))?(?'version' \[(?:(?:(?&ver_prefix) )?(?:(?'_ver'[\da-zA-Z]+)(?:\.(?&_ver))+|\d\d\d\d-\d\d-\d\d(?:T\d+)?)|(?&ver_prefix)( (?:[A-Z]|\d+|early))?)\])?(?'part' \(Dis(?:c|k) \d+\))?(?'language' \((?'_lang'(?:F-)?(?:Ja|En|Fr|De|Es|It|Nl|Ca|Fi|No|Sv|Da|Zh(?:-Hant|-Hans)?|Pt|Ru|Ko|Pl))(?:,?(?&_lang))*\))?(?'randomshit'(?: \[DEMO\])?(?: \[Sample\])?(?: \(Promo\))?(?: \(Unl\))?)(?'features' \[(?'_feat'[a-zA-Z]+)(?:, ?(?&_feat))*\])?(?'ext'\.(?:gbc|gb|nsp|xci|(nkit\.)?rvz|gcz|wbfs|wad|gba|type|cia|3ds|nds|nes|sfc|smc|n64|z64|wux|gg|md|sms|iso|pce|chd))$
/
gm

Description

this is some cursed shit, but it does work. I use it to check whether all my ROMs have valid names or not. Makes it easier to read and, more importantly, deduplicate.

Submitted by Riedler - 6 months ago (Last modified 5 months ago)