Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要RegEx替换帮助吗_Regex_Vb.net - Fatal编程技术网

需要RegEx替换帮助吗

需要RegEx替换帮助吗,regex,vb.net,Regex,Vb.net,假设我有一个html字符串,如下所示: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html dir='ltr' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://ww

假设我有一个html字符串,如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html dir='ltr' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'> <head> </head> <body> <p>GRANDMÈRE Break the fillets of the saucepan on a double and shaped into neat pieces and stir it boil hard, or of nutmeg and salt. Throw them fry as a few inches by one in this very well. Put the whites of butter by three. Put some artichoke-bottoms cooked green</p> <p>darkly colored on half with a little flour MY_IDENTIFIER and midrib. Put a hot for each side of vanilla cream as you cannot give it, and dish is a cauliflower, which you have not very useful sauce from the inside with a little nutmeg, and serve with the King of water</p> <p>dining-room. At the meat. STUFFED CAULIFLOWER SOUP (BELGIAN RECIPE) Take three quarters of tying the juice of ham. Keep the pot, so as being interpreted, means that time put them into four bay salt, and chopped. When the better to sprinkle in the tomato much as many crescents one of</p> <p>touch the rabbit to put quickly in. A white wine glass cups and pour over them, cut them in salt, pepper, and fill them in a pint of the liquor; it is a poached on slowly, without a layer of an egg on the yolks, and mix very clean, while</p> <p>CAKE, EXCELLENT FOR PASTRY Equal quantities of red wine. Stew your taste, use that, with extract and salt and ham, mushrooms when the mold and dip them a good red wine. This dish with pepper and place meat and serve with a good foundation for twenty potatoes, and potato, some</p> <p>half-an-hour. GOLDEN RICE Put them very little MY_IDENTIFIER book on a glass dish that way. CABBAGE WITH CHEESE Every one and season it up with not enough to make a pat of butter, each round quickly. Or add, instead of fresh lean and let it every now and put it melts</p> <p>leek, and over it, a half a fireproof cases from burning. CHOU-CROUTE Take the salad you take out the amount of cream is not get in four, about three-and-a-half pints of the middle of this sauce some chopped almonds, chopped parsley and mix it in your pieces of grated cheese</p> <p>sides. In four or flageolets, and stir in company with flour, and let it out, and pour over all, chop your vinegar to half a lemon--this would do not quite, add the edges. Steep them in a tablespoonful of butter and mustard. Take it in salted water; and, crumbling out</p> <p>care that it in which you have seasoned with an equal size, mix MY_IDENTIFIER these are well with the fermentation has a custard. Put the top with a very carefully, so that you have added at a sieve; or, for at home than thick. Then fry the custard as you prepare</p> <p>stuffing into a fireproof dish, and fry them to picnics, or marjoram with this MY_IDENTIFIER way besides parsley. Roll them out neatly with vanilla, a tablespoonful of mustard, pepper and salt, then pour it all cooked, and it to be ready to keep it simmer it over and salt. The original</p> </body> </html> GRANDMÈRE将平底锅的鱼片放在双层锅上,切成整齐的小块,然后将其煮沸,或者用肉豆蔻和盐搅拌。在这个井里把它们炸成几英寸见方。把黄油的白色调三。把一些朝鲜蓟底部煮成绿色

用一点面粉和中脉涂成深色。在香草奶油的每一面都放一个热的,因为你不能给它,这道菜是一个花椰菜,里面没有很有用的酱汁和一点肉豆蔻,和水之王一起食用

餐厅。看看肉。填充花椰菜汤(比利时食谱)需要四分之三的火腿汁。保留的锅,因此被解释为,意味着时间把他们放入四湾盐,并切碎。最好在西红柿上撒上多个月季一个

摸摸兔子,把它迅速放进去。一杯白葡萄酒,倒在上面,加入盐、胡椒,然后倒入一品脱白酒;它是一种慢慢水煮的,蛋黄上没有一层鸡蛋,混合时非常干净

蛋糕,非常适合制作等量红酒的糕点。炖你的味道,用那个,用提取物和盐和火腿,蘑菇发霉时,蘸它们一个很好的红酒。这道菜有胡椒和肉馅,配上二十个土豆和土豆的好基础,有些是< /P> 半小时。金米就这样把我的书放在一个玻璃盘子里。卷心菜和奶酪每一个和季节,它没有足够的拍黄油,每一轮快速。或者加入,而不是新鲜的瘦肉,让它每隔一段时间就融化

韭菜,在它上面,有半个防火箱,防止燃烧。CHOU-CROUTE拿沙拉你拿出来的奶油量不是四分之一,大约三品脱,中间放一些切好的杏仁,切好的欧芹,然后混合在你的碎奶酪里

双方。在四个或四个鸡蛋里,和面粉一起搅拌,把它放出来,倒在上面,把醋切成半个柠檬——这不太合适,加上边缘。在一汤匙黄油和芥末中浸泡。在盐水中服用;然后,崩溃了

注意用同样大小的调味品调味,把这些调味品和发酵好的奶油冻混合在一起。放在上面用一个非常小心的筛子,这样你就有了加在筛子上的;或者,在家里比厚。然后一边准备一边煎蛋羹

把它们塞进一个防火的盘子里,然后把它们煎到野餐时吃,或者除了欧芹之外,我还喜欢吃马郁兰。将它们与香草、一汤匙芥末、胡椒和盐一起整齐地滚出来,然后将它们全部倒入煮熟的食物中,准备好继续炖,然后加盐。原著

我需要找到p标签,如果文本包含“MY_IDENTIFIER”,那么对该文本进行一些操作,并用一些文本替换该文本

在这里,我知道如何使用regex查找带有文本的段落标记。我可以循环匹配,并可以根据需要对文本进行操作。我想知道如何用另一个文本替换匹配项

在上面的例子中,我在第2、第6、第9和第10段有“我的_标识符”。假设我想将第2段文本替换为

<p>2nd paragraph text</p> 第2段案文

第6段案文如下:

<p>6th paragraph text</p> 第6段案文

等等

到目前为止我掌握的代码

Imports System.Text.RegularExpressions Module modMain Sub main() Dim fileContents As String fileContents = My.Computer.FileSystem.ReadAllText("C:\temp\a.html") Dim paras As MatchCollection = Regex.Matches(fileContents, "<p>(.+?MY_IDENTIFIER.+?)</p>") Dim TxtFound As String For Each oMatch As Match In paras TxtFound = oMatch.Groups(1).Value 'do some manipulations with txtfound '... 'replace the txtfound with some other text Next 'Save the file again End Sub End module 导入System.Text.RegularExpressions 模块modMain 副标题() 将文件内容设置为字符串 fileContents=My.Computer.FileSystem.ReadAllText(“C:\temp\a.html”) 如MatchCollection=Regex.Matches(fileContents,“(.+?MY_IDENTIFIER.+?)

”) 找到作为字符串的Dim TXT 将每个oMatch视为第 TxtFound=oMatch.Groups(1).Value '使用txtfound执行一些操作 '... '将找到的TXT替换为其他文本 下一个 '再次保存文件 端接头 端模块
感谢您的帮助。

我将首先尝试通过全局匹配查找所有段落:

my @matches = ($string =~ m!<p>(.*?)</p>!sig);
foreach(@matches) {
  #keep a copy for substitution below
  my $before = $_;

  #if the identifier is found, replace it
  if($_ =~ s!MY_IDENTIFIER!replacement text!is) {
    #then take the newly replaced text, and replace it in your original $string variable
    $string =~ s!$before!$_!is;
  }
}