1

HTMLコンテンツに関連するパターンを見つけて置き換えるC#正規表現を作成しています。私はそのようなすべてのものを取得する必要があります:

<table border=0 align=center id=mytable5>

そのように修正:

<table border="0" align="center" id="mytable5">

私はこれを試しました:

String pattern = @"\s(?<element>[a-z])=(?<valeur>\d+?[a-z])\s?[\>]";
String replacePattern = "${element}=[\"]${valeur}[\"]";
html = Regex.Replace(html, pattern, replacePattern, RegexOptions.IgnoreCase);

しかし絶対に効果はありません。どんな助けでも大歓迎です。皆さん、ありがとうございました


実際にはキングキング、正規表現に問題があります

<table border=0 align="center" id="mytable5">

あげる

<table border="0" align=""center"" id=""mytable5"">

そのため、正規表現はこれをチェックする必要があります

[a スペース][az]=[a-z0-9][a スペースまたは '>']

4

2 に答える 2

0
var html = "<table border=0 align=center id=mytable5>";
html = Regex.Replace(html, @"=\s*(\S+?)([ >])", "=\"${1}\"${2}", RegexOptions.IgnoreCase);
于 2013-08-29T08:19:20.143 に答える