1

このコードから「Home」または「Home」というテキストを取得する必要があります。

<%@ Page Title="<%$ GetText: '**Home**' %>" Language="C#" ..%>
<asp:Button Text="<%$ GetText: '**Home**' %>"/>
<asp:Button Text='<%$ GetText: "**Home**" %>'/>
<asp:Button Text="<%$GetText:'**Home**'%>"/>
<asp:Button Text='<%$GetText:"**Home**"%>'/>

これを見つけるための正規表現はありますか?

もちろん、「<%$ GetText:」または「<%$ GetText:」を1行ずつ検索することはできますが、もっと賢い人がいるかもしれません:)

どうも

4

3 に答える 3

1

結果を取得し、それらを介して相互作用します。これはGetTextの任意のcAsEに一致し、一重引用符または二重引用符内のすべてを取ります(逐語的な文字列を使用すると、多くのエスケープ文字も節約できます)。

try {
    Regex regexCard = new Regex(@"([Gg][Ee][Tt]{2}[Ee][Xx][Tt]):\s*(['""""]([^'""""]+)['""""])");
    Match matchResults = regexCard.Match(subjectString);
    while (matchResults.Success) {

        //if i is 0 it returns the entire match
        //if i is 1 it returns the first capture group in this case "gettext" without the quotes.
        //if i is 2 it returns the second capture group, everything after <:><0-1 whitespace> including the first <' or "> until it hits a <' or "> (also includes this)
            //if i is 3 it returns the same but without the quotes.
        //you can move parentheses around or make more to create more capture groups to get the text you want.
        if(matchResults.Groups[i].Success)
        {
            string value = matchResults.Groups[i].Value;
        }
        matchResults = matchResults.NextMatch();
    } 
} catch (ArgumentException ex) {
    // Syntax error in the regular expression
}
于 2011-04-08T01:36:48.683 に答える
0

この正規表現は、グループ1内のこれらの各例からホームを取得します。

\*\*(\w+)\*\*
于 2011-04-05T17:08:13.817 に答える
0

正規表現:

GetText:\s*[\'\"]([^\'\"]+)[\'\"]

System.Text.RegularExpressionsからの.NETの名前付きキャプチャを使用する場合、正規表現は次のように変更できます。

GetText:\s*[\'\"](?<mytext>[^\'\"]+)[\'\"]

...そしてあなたのターゲットテキストはマッチグループ「mytext」にあります

于 2011-04-05T17:12:45.207 に答える