正则表达式匹配以空格字符开头的行

时间:2016-03-11 10:21:24

标签: php regex search

3.2 Mark one answer
You must NOT sound your horn
 between 10 pm and 6 am in a built-up
area
 at any time in a built-up area
 between 11.30 pm and 7 am in a builtup
area
 between 11.30 pm and 6 am on any
road
Vehicles can be noisy. Every effort must be
made to prevent excessive noise, especially
in built-up areas at night. Don’t

正则表达式

/^ ([\w-,@\.?:=+&%$£@"'’\s ]+)/gmi

运行上面的正则表达式不会产生任何结果。我想要行

我希望选项为

between 10 pm and 6 am in a built-up
area

at any time in a built-up area

between 11.30 pm and 7 am in a builtup
area

between 11.30 pm and 6 am on any
road

2 个答案:

答案 0 :(得分:0)

如果你真的需要所有以单个空格字符开头的行,你可以使用这个简单的正则表达式:

/^ (.*)$/gm

说明:

- "/" = Start of regular expression
- "^" = Match beginning of line
- " " = Match one space character
- "(.*)" = Match any sequence of characters and remember match
- "$" = regex ends at end of line
- "/" = End of regular expression
- gm = match [g]lobally and treat string as [m]ultiple lines

如果没有修饰符“m”,则字符“^”将匹配字符串的开头,“$”将匹配字符串的结尾。

答案 1 :(得分:0)

具有Just add this in start of the function where you are writing send email code $config = Array( 'protocol' => 'sendmail', 'mailtype' => 'html', 'charset' => 'utf-8', 'wordwrap' => TRUE ); $this->email->initialize($config); Email will forward but error same error will show 功能的解决方案。
(我要感谢WiktorStribiżew提醒我关于水平/垂直空白字符preg_match_all\h

\v

http://php.net/manual/en/regexp.reference.escape.php http://php.net/manual/en/regexp.reference.assertions.php