我正在尝试使用正则表达式将所有内容与关键短语进行匹配。基本上,它正在查看电子邮件,我希望它能在对话历史之前返回所有内容。
我一直在尝试使用(?:^|\W)From:(?:$|\W)([A-Z][a-z]*)[\s-]([A-Z][a-z]*)
停在From: Dave Patel
(在下面的示例中)并匹配之前的所有内容。
下面的示例文字,每当我搜索时,我只能返回前一行或两行。
This is just some test text.
Many thanks,
James Jones
Some company
51 made up street
The world
From: Dave Patel
Sent: 08 December 2017 14:57
To: Clare Jones <Clare.Jones.com>; Paul Smith <paul.smith@company.com>
Subject: Re: Files
Well done! Let me know when implemented if you want me to test.
From: Dave Patel
Sent: 08 December 2017 14:57
To: Clare Jones <Clare.Jones.com>; Paul Smith <paul.smith@company.com>
Subject: Re: Files
The fox jumps over the lazy dog
Joseph Smith
一家公司 bla bla blaaaa
答案 0 :(得分:0)
试试这个正则表达式
API\Response\MediaLikersResponse Object
(
[httpResponse] => GuzzleHttp\Psr7\Response Object
(
[reasonPhrase:GuzzleHttp\Psr7\Response:private] => OK
[statusCode:GuzzleHttp\Psr7\Response:private] => 200
[headers:GuzzleHttp\Psr7\Response:private] => Array
(
[Content-Type] => Array
(
[0] => application/json
)
)
[headerNames:GuzzleHttp\Psr7\Response:private] => Array
(
[content-type] => Content-Type
[vary] => Vary
[cache-control] => Cache-Control
[pragma] => Pragma
[expires] => Expires
[content-language] => Content-Language
[date] => Date
[set-cookie] => Set-Cookie
[connection] => Connection
[x-encoded-content-encoding] => x-encoded-content-encoding
[x-encoded-content-length] => x-encoded-content-length
)
[protocol:GuzzleHttp\Psr7\Response:private] => 1.1
[stream:GuzzleHttp\Psr7\Response:private] => GuzzleHttp\Psr7\Stream Object
(
[stream:GuzzleHttp\Psr7\Stream:private] => Resource id #149
[size:GuzzleHttp\Psr7\Stream:private] => 0
[seekable:GuzzleHttp\Psr7\Stream:private] => 1
[readable:GuzzleHttp\Psr7\Stream:private] => 1
[writable:GuzzleHttp\Psr7\Stream:private] => 1
[uri:GuzzleHttp\Psr7\Stream:private] => php://temp
[customMetadata:GuzzleHttp\Psr7\Stream:private] => Array
(
)
)
)
[_objectData:LazyJsonMapper\LazyJsonMapper:private] => Array
(
[users] => Array
(
[0] => Array
(
[pk] => xxxx
[username] => x
[full_name] => x
[is_private] =>
[profile_pic_url] => x
[is_verified] =>
)
[1] => Array
(
[pk] => x
[username] => x
[full_name] => x
[is_private] => 1
[profile_pic_url] => x
[profile_pic_id] => x
[is_verified] =>
)
[2] => Array
(
[pk] => x
[username] => x
[full_name] => x
[is_private] => 1
[profile_pic_url] => x
[profile_pic_id] => x
[is_verified] =>
)
)
[user_count] => 2
[status] => ok
)
)
我认为这个正则表达式的结果中的第1组是您正在寻找的。 p>
从您的示例中,第1组将是:
(.*?)From:(?:$|\W)([A-Z][a-z]*)[\s-]([A-Z][a-z]*)