[pcre-dev] Matching file contents as one string using PCRE_D…

トップ ページ
このメッセージを削除
著者: pcunite
日付:  
To: pcre-dev
題目: [pcre-dev] Matching file contents as one string using PCRE_DOTALL
I have read the entire PCRE documentation and have not found something that
states clearly what I'm looking to do. The documentation says: "By default,
PCRE treats the subject string as consisting of a single line of characters
(even if it actually contains newlines)." That is what I want to hear, but it
is not working out in practice. Testing version 8.32.

Goals:
1. Load a text file into a std::wstring buffer.
2. Have no regard for the concept of "lines". One big string is fine.
3. Use Positive Lookahead to find terms in ANY order.
4. I don't ever care about capturing or using LookBehinds.
5. Any character before or after the query terms is fine.

Regex:
Thus I have come up with this: (?=.*hello.*)(?=.*world.*)

Sample data from file.txt:
First line, hello present.
Second with world present.

Please verify this Solution:
However, it only seems to work if I set PCRE_DOTALL. What are the consequences of
using this flag? Is there a better way? I don't really want to use the ^$ combo as
that is the notion of lines, no? They don't work anyway.