new Regex
()内をstring型にしてメソッドにして投げるとエラーが返されました。
通常
string source ="<!DOCTYPE html><html lang~~~";
Regex reg = new Regex("http://panda.com/(\\d\\d\d\d\\d|\\d\\d\\d\\d\\d)",
RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match match = reg.Match(source);
if (match.Success)
textBox8.Text = match.Groups[0].Value.Trim();
失敗例
private void Tikan(string source, string tikan){
Regex reg = new Regex(tikan,
RegexOptions.IgnoreCase | RegexOptions.Singleline);
Match match = reg.Match(source);
if (match.Success)
textBox8.Text = match.Groups[0].Value.Trim();
}
また、できれば\d\d\dなどではなく、桁制限の無い連続する半角数字としたいです。
tikan
の値が分かりませんので、Console.WriteLine(tikan);
などで確認してみてください。http://panda.com/(\d\d\d\d|\d\d\d\d\d)
と表示されなければおそらく引数が間違っています。 – pgrho 15年11月28日 6:42source
とtikan
の値、具体的な「エラー」の内容を書いてください – suzukis 15年11月28日 10:53