c#regex [英] c# regex

查看:90
本文介绍了c#regex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果字符串: 我期望五百美元(abc)(xyx)

然后只获得:xyz


此正则表达式:  \((。+)\)+ $


return:  (abc)(xyx)



谢谢

解决方案

你想2学习,


如果你只是想要获得xyz,你可以尝试下面的代码。

 Regex regex = new Regex(@"(?< = \()。+?( ?= \))",RegexOptions.RightToLeft); 
匹配匹配= regex.Match("(abc)(xyx)");
Console.WriteLine(match.Value);


最好的问候,


Wendy


how can I get last occurrence of "()"

if the string : I expect five hundred dollars (abc) (xyx)

then get only :xyz

this regex : \((.+)\)+$

return : (abc) (xyx)

Thanks

解决方案

Hi want 2 Learn,

If you only want to get xyz, you could try the code below.

  Regex regex = new Regex(@"(?<=\().+?(?=\))", RegexOptions.RightToLeft);
            Match match = regex.Match("(abc) (xyx)");
            Console.WriteLine(match.Value);

Best Regards,

Wendy


这篇关于c#regex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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