正则表达式问题 [英] Issue with regular expression

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

问题描述

你好,

我在正则表达式匹配中遇到问题...

Hello,

I have an issue in regular expression matching...

string x = "user = 'sa' password='eX65dere' server = 'localhost'";
Regex rx = new Regex("password=\'([a-zA-Z0-9]\\_+)\'");
var r = rx.Match(x);
            if (r.Groups.Count > 0)
            {
                var g1 = r.Groups[0]; 
                label1.Text = g1.ToString();
            }



在执行此操作时,我收到以下错误消息. 解析密码="([[a-zA-Z0-9] \ _ +)''-无法识别的转义序列\ _ .有人可以帮我吗?

谢谢
Sebastian



while executing this, I have got the following error message. parsing "password=''([a-zA-Z0-9]\_+)''" - Unrecognized escape sequence \_. Can anyone help me on this?

Thanks
Sebastian

推荐答案

我已经通过如下更改表达式来解决了这个问题...
I have solved this by changing the expression as follows...
Regex rx = new Regex(@"password='([a-zA-Z0-9\\%^&_*]+)\'");



--------------


我又有一个问题...这是我更新的表达方式...



--------------


again i have another question... Here is my updated expression...

string x = "user = 'sa' password='e X65dere!@#


%^& *()'server ='localhost'"; Regex rx = Regex( @"
%^&*()' server = 'localhost'"; Regex rx = new Regex(@"password=\'([a-zA-Z0-9\\!@#


%^& * |()_'" *-+ {}&.; ../?:〜`\ [\\\\\\] +)\'"); var r = rx.Match(x); 如果(r.Groups.Count > 0 ) { var g1 = r.Groups [ 0 ]; MessageBox.Show(g1.ToString()); }
%^&*|() _'""*-+{}<>,.;/?:~`\[\]\\\\]+)\'"); var r = rx.Match(x); if (r.Groups.Count > 0) { var g1 = r.Groups[0]; MessageBox.Show(g1.ToString()); }



在这种情况下,它会与每个小&大写字母,数字和特殊字符( = 除外).如果密码包含 = ,则表达式失败...请您帮忙?

问候
塞巴斯蒂安



In this case it will match for every small & large cap letters, numbers and special characters except = . If the password contains = the expression fails... can you please help?

Regards
Sebastian


这篇关于正则表达式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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