Community Patterns

Community Library Entry

4

Regular Expression
Created·2020-03-03 01:56
Flavor·PCRE (Legacy)

/
(^( +|)\[(?<name>[^#;\r\n]+)\])|(^( +|)(?<key>[^\[\]\r\n=#;]+)( |)=( |)(?<value>[^#;\\\r\n]*(?:\\.[^#;\\\r\n]*)*))|((#|;)(?<comm>.+)$)
/
gm
Open regex in editor

Description

Created for purpose of reading an INI file in C# applications. Supports comments and comment escape characters. I plan to add more escape characters (such as =).

s    - Section
scp  - Section Comment Prefix
sc   - Section Comment
k    - Key
v    - Value
kvcp - KeyValue Comment Prefix
kvc  - KeyValue Comment
cp   - Comment Prefix
c    - Comment

I am open to any suggestion that may improve upon this regex, and/or would allow me to learn more. <br />

Created by Raxdiam
Submitted by Raxdiam