开发者

Regex match element left before match

I got a file with the following structure:

[section1]
item1 = text1
item2 = text2
item3 = text3

[section2]
item1 = text4
item2 = text5
item3 = text6

...

and i will find the section to a text. e.g. text is "text6" it should return "section2".

I t开发者_开发百科ied:

content.scan(/(^\[.*?\]).*?#{text}/m)

but that is only returning the first section of the file :/ (i use ruby)


/\[([^\[]*?)\][^\[]*?text6/m

This should work :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜