如何用一些模式匹配替换字符串 [英] how can i replace a string with some pattern matching

查看:69
本文介绍了如何用一些模式匹配替换字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



任何人都可以帮助我在c#

中使用正则表达式来获得解决方案基本上我必须在 * p0x0Y 之前添加一些文字模式。在这个模式中,p,x,y将是固定值,0可以被任何数字替换。



i必须编辑

 < span class =code-keyword> string  str =   ?? l8c1E? * p0x0Y  



在此字符串中* p0x0Y可以是* p1x1Y或* p2x2Y。



和编辑后的输出应该是* p0x0Y格式



  string  output =   18c1EXXX  * p0x0Y  





提前致谢。

解决方案

尝试:

  string  str =   l8c1E * p0x0Y; 
string output = Regex.Replace(str, @ (\ * p\dx \ dY) @ XXX


1);







嗨OriginalGriff,你的解决方案对我有用,现在我想再问一件事......我必须在下面的文字中将左侧字符串替换为右侧字符串..在本文中左箭头标志是一个符号我无法复制粘贴,所以我用文字写了它,它只是一个符号。所以请给我正则表达式代码来替换它。左箭头标志* p0x0Y - >左箭头标志xxx左箭头标志 * p0x0Y我清楚我的要求,原件?





如果不知道确切的字符,我不能确定,但是...点字符匹配任何东西,所以它可能是你想要的是:

  string  output = Regex.Replace(str, @ (。)(\ * p\dx \ dY) @  


< BLOCKQUOTE> 1XXX

Hi
Can anybody help me to get the solution using regular expression in c#
basically i have to add some text before *p0x0Y pattern . In this pattern p,x,y will be fix value and 0 can be replace by any number .

i have to edit a

string str= "l8c1E*p0x0Y"


In this string *p0x0Y can be *p1x1Y or *p2x2Y .

and after editing output should be according *p0x0Y format

string output = "18c1EXXX*p0x0Y"



Thanks in advance .

解决方案

Try:

string str = "l8c1E*p0x0Y";
string output = Regex.Replace(str, @"(\*p\dx\dY)", @"XXX


1");




"Hi OriginalGriff , Your solution worked for me , now i want to ask one more thing ... i have to replace left side string into right side string in below text .. In this text "left arrow sign" is one symbol which i could not copy paste so i wrote it in text ,its just one symbol. So please give me regular expression code to replace it . "left arrow sign"*p0x0Y --> "left arrow sign"xxx "left arrow sign"*p0x0Y Am i clear about my requirement , Original ?"


Without knowing the exact character, I can't be sure, but...the dot character matches anything, so it might be that what you want is:

string output = Regex.Replace(str, @"(.)(\*p\dx\dY)", @"


1XXX


这篇关于如何用一些模式匹配替换字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆