使用Regex在C#中使用AND和OR运算符 [英] using AND and OR operator in C# using Regex

查看:127
本文介绍了使用Regex在C#中使用AND和OR运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友

我想在使用正则表达式打开括号之前和之后找到空格,同时还有一些例外情况。





for Eg

ab7cd(te8st)必须匹配

和312(48)应该被跳过或它不应该得到匹配



我试过这个:

 [A-zÀ-ú0-9] + \ \\ [([A-zÀ-ú0-9] + | [A-zÀ-ú0-9] + \\([A-zÀ-ú0-9] + | [A-zÀ-ú0-9] + \\([A-zÀ-ú0-9] + | [^ A-zÀ-ú0-9] + \\(^ [A-zÀ-ú0-9] + \\)





但不工作





谢谢并且问候

Bala

解决方案

假设你想要一个强制性的字母数字字符混合,包括开始括号之前或之后的可选空格,那么试试这个:

 @^ [a-zA-Z] + \d + [a-zA-Z \ n] * | [a-zA-Z \ n ] * \d + [A-ZA-Z] + \d * \s * \\ (\s * [A-ZA-Z] + \d + [A-ZA-Z\d] * \)| \([A-ZA-Z\d] * \d + [一-Za-Z] + \d * \)


Hi Friends
I want to find space between before and after opening brackets using regex at the same time there are some exceptional case.


for Eg
ab7cd(te8st) has to be get matched
and 312(48) should be get skipped or it should not get matched

I tried this:

[A-zÀ-ú0-9]+\\([A-zÀ-ú0-9]+|[A-zÀ-ú0-9]+\\( [A-zÀ-ú0-9]+|[A-zÀ-ú0-9]+\\( [A-zÀ-ú0-9]+|[^A-zÀ-ú0-9]+\\(^[A-zÀ-ú0-9]+\\)



but its not working


Thanks and regards
Bala

解决方案

Assuming you want a compulsory mix of alphanumeric characters including optional space before or after the opening bracket, then try this:

@"^[a-zA-Z]+\d+[a-zA-Z\d]*|[a-zA-Z\d]*\d+[a-zA-Z]+\d*\s*\(\s*[a-zA-Z]+\d+[a-zA-Z\d]*\)|\([a-zA-Z\d]*\d+[a-zA-Z]+\d*\)


"


这篇关于使用Regex在C#中使用AND和OR运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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