Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex to match multiple MBCS strings on any line
    text
    copied!<p>I'm looking for a regex to match only MBCS strings inside of a C++ project. Those are strings contained in double quotes without a <code>L"..."</code> or <code>_T("...")</code> specifier. There can be multiple quotes on any line of code. Strings can contain escaped substrings that shouldn't end the match. Here are a few examples:</p> <pre><code>"This is a MBCS string"; // "This is a MBCS string" match _T("This is maybe a unicode string"); // no match L"This is a unicode string"; // no match "These both" + "should match"; // "These both" and "should match" match "This is a \"quoted\" string"; // "This is a \"quoted\" string" match </code></pre> <p>I have a regular expression than can handle all of this fine using negative lookbacks <code>(?&lt;!#include )(?&lt;!_T\()(?&lt;!\\)(?&lt;!L)\"(.*?)\"(?&lt;!\\\")</code> but it gets more complicated yet. It starts to have problems with mixing of string types on one line.</p> <pre><code>_T("Maybe this") + "is a match"; // "is this" match but instead would match ") + " do_something(_T("This doesn't match")) + do_something("but this does match"); // "but this does match" match but instead it matches ")) + do_something(" </code></pre> <p>How can I have the regular expression not match on <code>_T("")</code> and <code>L""</code> words but still match them to eat the end quote without returning it as a match?</p> <p>Edit: This regex, <code>(?:_T\(\"[^\"]+\"\).*?|L\"[^\"]+\".*?)*(?&lt;!#include )(?&lt;!_T\()(?&lt;!L)(?&lt;!\\)\"(.*?)\"(?&lt;!\\\")</code>, nearly does the job but there is one more test case that's failing that I hadn't thought to include originally.</p> <pre><code>_T("don't match this") + _T("or this"); // shouldn't match anything, matches ") + _T(" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload