私はパスカル文字列のリテラル入力を次のパターンに一致させようとしています:@"^'([^']|(''))*'$"
しかし、それは動作しません。パターンの何が間違っていますか?パスカルのような文字列リテラル正規表現
public void Run()
{
using(StreamReader reader = new StreamReader(String.Empty))
{
var LineNumber = 0;
var LineContent = String.Empty;
while(null != (LineContent = reader.ReadLine()))
{
LineNumber++;
String[] InputWords = new Regex(@"\(\*(?:\w|\d)*\*\)").Replace(LineContent.TrimStart(' '), @" ").Split(' ');
foreach(String word in InputWords)
{
Scanner.Scan(word);
}
}
}
}
私は、任意のパスカル・エントリのコメント入力文字列を検索する空白に置き換える、その後、私は次のようにそれらを一致させるためにサブストリングに入力を分割:
private void Initialize()
{
MatchingTable = new Dictionary<TokenUnit.TokenType, Regex>();
MatchingTable[TokenUnit.TokenType.Identifier] = new Regex
(
@"^[_a-zA-Z]\w*$",
RegexOptions.Compiled | RegexOptions.Singleline
);
MatchingTable[TokenUnit.TokenType.NumberLiteral] = new Regex
(
@"(?:^\d+$)|(?:^\d+\.\d*$)|(?:^\d*\.\d+$)",
RegexOptions.Compiled | RegexOptions.Singleline
);
}
// ... Here it all comes together
public TokenUnit Scan(String input)
{
foreach(KeyValuePair<TokenUnit.TokenType, Regex> node in this.MatchingTable)
{
if(node.Value.IsMatch(input))
{
return new TokenUnit
{
Type = node.Key
};
}
}
return new TokenUnit
{
Type = TokenUnit.TokenType.Unsupported
};
}
パスカルのような文字列リテラルとは何ですか? [これ?](http://en.wikipedia.org/wiki/String_literal#Double-up_escape_sequence) –
入力文字列と期待される結果を表示できますか? – Toto