排除带有特定数字的输入字符串的正则表达式
Regex that excludes input strings with specific numbers
例如,我有以下4个输入:
{168,3816,2012,[04,14]}
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}
{168,33409,2011,[14]}
我想要排除输入4,因为它在第一个逗号后面有数字33409,所以我的最终结果将是:
{168,3816,2012,[04,14]}
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}
我想出了以下正则表达式.*,(?!(33409))'d{5},.*
,但它未能包括第一个输入:{168,3816,2012,[04,14]},这是因为我指定了范围d{5}。使用'd+或'd{0,5}不起作用。
我希望我的正则表达式能够排除多个数字,例如输入数字33409或3816后的第一个逗号。所以最终结果将是:
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}
感谢大家的反馈。我意识到我需要给出问题的更多细节才能得到正确的答案。下面是对这个问题的详细解释。我有一个带有元数据的图书标题列表。元数据由ItemClass,Itemkey,ItemPublicationyear and ItemCategory
组成。书名是返回格式如下:
booktitle {itemclass,itemkey,itempublicationyear,[itemcategory]}
//ItemCategory can have mult. values
REGEX形式的过滤器应用于{}中的元数据,以向用户返回正确的标题。
图书标题示例列表如下所示:
Business Liability Insurance 2011-12 {168,326,2011,[14,32]} //itemcategory with mult. values
Insurance Regulation 2013 {168,37955,2012,[14,32]}
Financial Institutions {168,33734,2011,[14]} //itemcategory with just one value
Insider Trading Law {168,32645,2011,[04,14]}
Business Liability Insurance {168,32647,2011,[14,32,45]}
用户请求可以由一个或多个过滤器组成。例如,用户可以请求属于itemclass 102,33,168的图书标题列表,因此REGEX将像这样:
(102|33|168),(.*),(.*),(.*) //I didn't use (102|33|168),(.*) because I want
the format of the expression to be ItemClass,ItemKey,ItemPublicationYear,ItemCategory
Another request with filter ItemCategory= 14 will look like this: (.*),(.*),(.*),'[((('d+),)*(14)(,'d+)*)']
If user applied both the ItemClass and ItemCategory filters the regex will look like this:
(102|33|168),(.*),(.*),'[((('d+),)*(14)(,'d+)*)']
我让它对所有过滤器都起作用。当用户想要使用过滤器来排除特定的图书通过应用itemkey过滤器,以便用户可以请求除项目键为32647、326的图书外的所有图书标题
Itemclasses Itemkey ItemPublicationYear ItemCategory Regex
------------------------------------------------------------------------------
All All All All (.*),(.*)(.*),(.*) //no filters applied
110,112 All All All (110|112),(.*),(.*),(.*)
All 38524 All All (.*),(38524),(.*),(.*)
All All 2004-2014 All (.*),(.*),2(0(0([4-9])|1([0-4]))),(.*)
All All All 24,21,27 (.*),(.*),(.*),'[((('d+),)*(24|21|27)(,'d+)*)']
110,112 38524 All 24,21,27 (110|112),(38524),(.*),'[((('d+),)*(24|21|27)(,'d+)*)']
您想要的最终结果没有得到适当的解释?
上面的输入都是字符串吗?
"{168, 3816, 2012,(04 14)}"
"{168年、38087年、2012年,[14日32]}"
"{168年、37955年、2012年,[14日32]}"
"{168年、33409年、2011年,[14]}"
你能回答以下问题吗?
你到底想要匹配什么?
要检查第一个逗号后的第一个数字是否不等于33409吗?
"我希望我的正则表达式能够排除多个数字"=>你的意思是这里的多个数字?
然而,从我的理解试试下面的regex
/{' d {3 }',(?:!(?: 33409 | 3816)) ' ' d {4}, [' d + ' ' d +]}
这将尝试匹配
{3 digit no, not equal to 33409 or 3816, 4digit no, [any digit no, any digit no]}
- 一种在javascript上获得具有两个输入(字符串)的散列键的方法
- 使用简单的角度滤波器来替换输入字符串中某些字符串的所有出现,而不考虑大小写和空格
- 将输入字符串附加到锚标记href
- 尝试通过输入字符串使程序停止运行
- 是否有可能/建议解析我的用户输入字符串 w 正则表达式
- 无法在末尾之前将输入字符串与“)”匹配
- Node.js' crypto.createSign() 的有效算法输入字符串
- 使用 PHP 填充引导输入 - 字符串变量中出现空格错误
- 手动输入字符串的 JSON 解析语法错误
- 按钮单击事件未将输入字符串传递给 MVC 控制器方法
- 从输入字符串中获取包含字符及其 ANSI 颜色的数组
- Unicode 规范化文件输入字符串
- 验证输入字符串并将其转换为新的 Date 对象
- 如何不输入字符串 JSF
- 通过按钮(asp.net)在textbox.value(JavaScript)中输入字符串
- 如何在用户输入字符串时获取$viewValue中的字符串
- 将输入字符串转换为GET变量
- 是否不可能在JavaScript中使用多行regex模式来指示输入字符串的开始
- 将用户输入字符串指定为javascript中的新变量名
- 我该如何编写一个正则表达式来接受任何输入字符串并只输出字母