PHP regular expression to match lines starting with a special character

前端 未结 2 1287
猫巷女王i
猫巷女王i 2020-11-29 10:18

I have a text file with some configuration value. There a comment starts with a # I am trying to find a regular expression pattern that will find out all the lines that star

2条回答
  •  失恋的感觉
    2020-11-29 11:02

    You can simply write:

    preg_match_all('~^#.*~m', $text, $m);
    

    since the quantifier is greedy by default and the dot doesn't match newlines by default, you will obtain what you want.

提交回复
热议问题