简体   繁体   English

正则表达式以匹配数字或特定词

[英]Regular Expression to match numeric OR specific word

I am trying to create a regular expression that handles 0-9 * or basically \\d* but also include the or (|) with an expression to handle a specific word. 我正在尝试创建一个处理0-9 *或基本上\\ d *的正则表达式,但还要包括带有处理特定单词的表达式的或(|)。 So the idea im shooting for should be this 所以我拍摄的想法应该是这样

\\d*|[Word] \\ d * | [字]

The reason i need this to happen is i have a filter textbox with my validator applied to it to prevent bogus data being entered, but the trick is i have the default text of the textbox set to what is to be entered into the box, such as "Enter Account." 我需要发生这种情况的原因是我有一个过滤器文本框,其中已应用验证程序,以防止输入虚假数据,但诀窍是我将文本框的默认文本设置为要在框中输入的内容,例如作为“输入帐户”。 I need the regular expression to handle \\d* for the account number validation and the | 我需要使用正则表达式来处理\\ d *以进行帐号验证和| part of the expression to allow the default text of the textbox to pass validation. 表达式的一部分,以允许文本框的默认文本通过验证。 I do checking on the back end so this default text wont break the app. 我会在后端进行检查,以便此默认文本不会破坏应用程序。 I have 3 filter boxes where i'll be using this expression..if possible. 我有3个过滤器框,如果可能的话,我将使用此表达式。

You basically have it, but lose the [] , which indicate character classes: 您基本上已经拥有了它,但是丢失了[]来指示字符类:

^\d*|word$

Also, you should anchor your validation expressions with ^ and $ . 另外,您应该使用^$锚定验证表达式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM