本文介绍了替换像x01这样的文本但不像\ x01 Regex C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试替换文件中的文本 - 我知道我可以在给定目录的文件中搜索并读取所有文本 - 然后使用替换函数但是如何让正则表达式测试器替换typeA的文本但不是\typeA的文本,请注意typeA之前的反斜杠。有一个简单的方法来做到这一点?我知道我可以检查\typeA并且我知道我可以检查这个类型A和getmatches但是这里的旋转是如何使用\取消匹配的东西是typeA可以以,{或者什么都不作为前缀除了在所有情况下,我想从更改中排除\typeA。只是一个FYI \不是这些文件中的转义字符。

Hello I am trying to replace text in files - I know I can search with in files of a given directory and read all text - then use replace functions but how do I get the regular expression tester to replace text of typeA but not text of \typeA , please note the backslash before typeA . Is there a simple method to do this ? I know I can check for \typeA and I know I can check for this typeA and getmatches but the spin here for me is how to unmatch the ones with the \ the thing is typeA could be prefixed by ",{, or nothing at all but in all cases I would like to exclude \typeA from the change. Just an FYI the \ is not an escape character in these files.

推荐答案

(?<!\\)\b\w+\b

应匹配每个没有前缀的单词\

这就是你要照顾的吗?

should match each word not prefixed by \
Is that what you are looking after?


string source = @"Hello I am trying to replace text in files - I know I can search with in files of a given directory and read all text - then use replace functions but how do I get the regular expression tester to replace text of typeA but not text of \typeA , please note the backslash before typeA . Is there a simple method to do this ? I know I can check for \typeA and I know I can check for this typeA and getmatches but the spin here for me is how to unmatch the ones with the \ the thing is typeA could be prefixed by "",{ or nothing at all but in all cases I would like to exclude \typeA from the change. Just an FYI the \ is not an escape character in these files. ";
string match = @"([^\\])typeA";
string replace = @"






只需将其粘贴在主要内容上,然后按编译和放大即可。执行



确保使用System.Text.RegularExpressions添加:



;



在顶部





Don



Just paste it in over what they have in main, and press "Compile & Execute"

Make sure you add:

using System.Text.RegularExpressions;

at the top


Don


这篇关于替换像x01这样的文本但不像\ x01 Regex C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 06:30