什么是空间的正则表达式 [英] What is regex for space

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

问题描述

在下面的代码中,正则表达式在从DDL中选择值时抛出错误。

验证表达式中存在一些错误。如何对此DDL中的数据使用正确的验证表达式。在DDL中有小字符, - ,括号和空格。



In the following code, the regular expression throws error on selection of a value from DDL.
There is some wrong in validation expression. How to use the correct validation expression for the data in this DDL. In DDL there is small characters, an -, brackets and space.

<asp:DropDownList ID="DropDownList7" runat="server"

        style="z-index: 1;top: 246px; left: 225px; position: absolute; height: 18px; width:148px"

               AutoPostBack="True"

             onselectedindexchanged="DropDownList7_SelectedIndexChanged">
         <asp:ListItem>SELECT</asp:ListItem>
         <asp:ListItem>(7-14 days)</asp:ListItem>
         <asp:ListItem>(4-8 days)</asp:ListItem>
    </asp:DropDownList>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server"  Display='None'

            ControlToValidate="DropDownList7" ErrorMessage="Select Delivery Days"

            ValidationExpression="[0-9 a-z \s \d-_ ][(][)]{1,50}" Font-Size="X-Small"></asp:RegularExpressionValidator>

推荐答案

空间的正则表达式是 \s

例如用于匹配字母数字和空格的正则表达式将是 Regex.Replace(q,@[^ a-zA-Z0-9 \ s],string.Empty);
The regex for space is \s.
For e.g. the regex for matching alphanumeric and spaces would be Regex.Replace(q, @"[^a-zA-Z0-9\s]", string.Empty);


^\s*(?=[a-zA-Z0-9'/\\&.-])([a-zA-Z0-9'/\\&.\s-]{3,})(?<=\S)\s*





^ #Start of string
\ s *#可选领先的空白,不要' t捕获。
(?= #Assert that ...
[a-zA-Z0-9 ' / \\& .-]#允许下一个字符,非空格

(#Match 捕获...
[a-zA-Z0 -9 ' / \\&。\ s - ] {3,}#

(?< = \ S)#断言前一个字符 空格
\s *#可选尾随空格,不要' t捕获。
^ # Start of string \s* # Optional leading whitespace, don't capture that. (?= # Assert that... [a-zA-Z0-9'/\\&.-] # the next character is allowed and non-space ) ( # Match and capture... [a-zA-Z0-9'/\\&.\s-]{3,} # ) (?<=\S) # Assert that the previous character is not a space \s* # Optional trailing whitespace, don't capture that.


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

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