2

以前に TPerlRegEx を使用したことがなく、正規表現を使用するのはこれが初めてです。

次のように、Delphi Xe2 で TPerlRegEx を使用して括弧と引用符を削除する小さな例を探しています。

入力文字列:

["some text"]

結果:

some text

単一行、ネストされたブラケットまたは引用符はありません。Regexbuddy を使用して正規表現を作成およびテストしましたが、結果が得られません。

4

2 に答える 2

5

これは Regex Buddy で動作します:

正規表現:

\["(.+?)"\]

交換:

$1

次のように使用します。

var
  RegEx: TPerlRegEx;
begin
  RegEx := TPerlRegEx.Create(nil);
  try
    Regex.RegEx := '\["(.+?)"\]';
    Regex.Subject := SubjectString;  // ["any text between brackets and quotes"]
    Regex.Replacement := '$1';
    Regex.ReplaceAll;
    Result := Regex.Subject;
  finally
    RegEx.Free;
  end;
end;

使い方:

Match the character "[" literally «\[»
Match the character """ literally «"»
Match the regular expression below and capture its match into backreference number 1 «(.+?)»
   Match any single character that is not a line break character «.+?»
      Between one and unlimited times, as few times as possible, expanding as needed (lazy) «+?»
Match the character """ literally «"»
Match the character "]" literally «\]»


Created with RegexBuddy
于 2013-04-11T13:28:34.267 に答える