使用正則表達式,(我使用的是PCRE的Autohotkey)如何匹配ini文件的部分?我不需要獲得個人密鑰 - 只是部分塊。正則表達式:返回ini節作爲字符串
我想出了這個,只要找到的部分後面有一個部分,它就會匹配,但如果它是最後一部分,它就會失敗。
iniregex := "ms)(?<=^\[keys\]).*(?=^\[)"
例子,我想要得到的部分,[keys]
的全部內容,而排除了意見,並忽略空行(它應該捕捉test=2
,然而,但不包括在該行的註釋:
[settings]
settings=0
;settings=1
[keys]
test=0
;test=1
test=2 ;comment
test=3
[nextsection]
this section has an empty and should be caught.
there is an empty line after this line, and it should be caught, too.
eof
I found this,但我不知道放在哪裏尋求節的名稱。
第一個正則表達式讓我像我想要的部分,但第二個似乎並沒有排除評論。 – bgmCoder 2013-03-18 03:13:22
在第一個正則表達式中,如何在'[keys]'之後和下一個'['? – bgmCoder 2013-03-22 21:53:23
@BGM你想用下面的換行符排除整個'[keys]'字符串嗎?你有什麼樣的換行符? '\ r \ n','\ n','\ r'? – speakr 2013-03-23 17:12:18