Reputation: 1207
I try to create a regex expression that can parse a ini-File.
But I want that the ini-values can be multiline!
Like that:
Wert1=Hallo
dsadasd
Wert2=Hi
Wert3=Heinirch Volland
I try it with this regex, but it doesn't work:
/.*=(.*)^.*=/gsm
Upvotes: 3
Views: 4626
Reputation: 24812
You could be using this PCRE regex :
/^.*=.*[^=]*$/gm
Try it here.
This relies on the absence of the s
ingle-line flag, be careful not to set it. The m
ultiline flag is also necessary, and g
lobal can be used if appropriate.
This matches from the start of a line containing an equal sign (^.*=.*
), then will match as many whole lines that do not contain an equal sign as it can ([^=]*$
, where [^=]
will match linefeeds).
Upvotes: 3
Reputation: 132
I guess you are trying to get all ini values, and to do that you can use this regex pattern:
/^(.*)=(.*)/gm
and you'll can access your values using groups, each group will retrieve to you key and value
Upvotes: 1
Reputation: 10786
You appear to be using Perl. Have you considered using Config::IniFiles? That module will handle parsing INI-type files for you, and has support for multiline parameters using heredoc syntax:
Parameter=<<EOT
value/line 1
value/line 2
EOT
Or, if you enable it with Config::IniFiles->new(..., -allowcontinue => 1);
, continuation lines:
[Section]
Parameter=this parameter \
spreads across \
a few lines
Upvotes: 0