正则表达式不区分大小写,且输入匹配 [英] Regex Case Insensitive with input match

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

问题描述

我正在尝试通过使用以下代码通过javascript分配正则表达式来对html输入进行验证:

I am trying to make validation for an html input by assigning via javascript a regex using the following code:

$("#"+field.field_id).attr("data-validation",'custom');
$("#"+field.field_id).attr("data-validation-regexp",field.regex);

如果我将正则表达式设置为

If I set the regex to

^(Server (\d{1,2}))$

然后它仅适用于输入"Server .."但是我希望输入服务器不区分大小写.就像服务器"或服务器"……我试图将^(Server(\ d {1,2}))$/i放进去,但是它不起作用.有什么想法吗?

Then it works only with input 'Server ..' But i want the input Server to work with case insensitive. Like 'SERVER' or 'sErver'...... I tried to put ^(Server (\d{1,2}))$/i but it doesn't work. Any ideas ?

推荐答案

您可以使用:

^([Ss][Ee][Rr][Vv][Ee][Rr] (\d{1,2}))$

使其不区分大小写.

输入模式中不支持 i (忽略大小写标志),因为它是在禁用了全局,ignoreCase和多行标志的情况下编译的.

There is no support of i (ignore case flag) in input pattern since it is compiled with the global, ignoreCase, and multiline flags disabled.

这篇关于正则表达式不区分大小写,且输入匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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