Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Java 8

"
(?<if>#if\((?<ifContents>[^\)]+)\))(?<ifResult>[\s\S]+?)(?=#elif|#else|#end)(?<elIf>#elif[\s\S]+?(?=#else|#end))?(?<else>#else([\s\S]+?(?=#end)))?[\s\S]*?#end
"
ig

Description

A basic if else parser. It automatically captures the if equation and the result. It supports if, elif, and else statements. Note: for elif statements part 2 is required. This is because Regex can't use one group to capture multiple elif statements.

Part 2 can be found here

Submitted by Rubeste - 3 years ago