I’m using ini files for an unusual purpose. I’ll have a key that consists of an `n separated list. Of course this is not “proper” use of an ini file. In my haystack, below, you can see that the first key first main content= is a normal key. I can use iniRead to get its content with no problem. However the key, first optional content= is messed up because of the line breaks. If I try to retrieve its content with iniRead, then I don’t get the list of fruits because it stops looking when it gets to the end of the line (at least I assume that’s the problem).
If I use iniRead to capture the entire [section] however, it does show the embedded lists, as desired.
My challenge is to get the embedded “sub lists” into variables… Really it’s just the first sub list that I need. I’ll then remove the key name and find the next one, and so on. It is relevant that the keys which are lists, all contain the word “optional” (lowercase) in the name of the key.
My thought is to have a RegEx that is like the following, which I've put on three lines for readability:
(non-captured group that isolates the first key name that contains ‘options’)
(captured group that contains my list)
(non-captured group that isolates the next key which is found, and therefor indicates that I’ve reached then end of the list).
Hopefully that makes sense. I can explain more about what I'm trying to accomplish, if it helps.
Code: Select all
haystack =
(
[My Key List]
first main content=The food eater's name is [n]. His favorite fruits are;
first optional content=
1 apples
1 bananas
0 cherries
1 oranges
0 mangoes
0 kiwis
second main content=He prefers them
second optional content=
1 fresh
0 canned
0 frozen
third main=[n] eats fruits
third optional=
1 daily.
0 weekly.
0 less often than he probably should.
)
needle =
RegExMatch(haystack, needle, outVar)
MsgBox outVar is`n`n|%outVar%|
ExitApp