0

ファイルパスを含む可能性のある文字列を解析しようとしています。正規表現ライブラリで C++ を使用しています。私は正規表現が苦手です。ここでは ECMAScript を使用します。

文字列の理由がわかりません:

「C:\Windows\explorer.exe C:\titi\toto.exe」

パターンに一致しません (実際には最初のものしか見つかりません)

(?:[a-zA-Z]\:|\\)(?:\\[a-z_\-\s0-9]+)+

すべての一致を見つけるためのより良いアイデアはありますか? ありがとう!

これが私のコードです:

wsmatch matches;
regex_constants::match_flag_type fl = regex_constants::match_default ;  
regex_constants::syntax_option_type st = regex_constants::icase             //Case insensitive
                                        | regex_constants::ECMAScript
                                        | regex_constants::optimize;

wregex pattern(L"(?:[a-zA-Z]\\:|\\\\)(?:\\\\[a-z_\\-\\s0-9]+)+", st);

// Look if matches pattern
printf("--> %ws\n", path.c_str());
if (regex_search(path, matches, pattern, fl) 
&& matches.size() > 0)
{
    for (u_int i =  0 ; i < matches.size() ; i++)
    {
        wssub_match sub_match = matches[i];
        wstring sub_match_str = sub_match.str();

        printf("%ws\n", sub_match_str.c_str());
    }
}   
4

2 に答える 2

0

次のようなものを使用できます。

.?:(\\[a-zA-Z 0-9]*)*.[a-zA-Z]*

http://regexpal.com/でテストしたところ、すべてのファイル パスが抽出されました。

于 2013-03-29T19:59:00.023 に答える