Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 排除带有特定数字的输入字符串的正则表达式_Javascript_Regex - Fatal编程技术网

Javascript 排除带有特定数字的输入字符串的正则表达式

Javascript 排除带有特定数字的输入字符串的正则表达式,javascript,regex,Javascript,Regex,例如,我有以下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]} {168,38087,2012,[14,32]} {1

例如,我有以下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]}
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}
我找到了以下正则表达式
*,(?!(33409))\d{5},.*
,但它没有包含第一个输入: {16838162012,[04,14]},这是因为我指定了范围d{5}。使用\d+或\d{0,5}无效

我希望我的正则表达式能够排除多个数字,例如在第一个逗号后带有数字33409或3816的输入。因此,最终结果将是:

{168,3816,2012,[04,14]}
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}
{168,38087,2012,[14,32]}
{168,37955,2012,[14,32]}

谢谢大家的反馈。 我意识到我需要给出问题的更多细节才能得到正确答案。 下面是对这个问题的详细解释。我有一个附有元数据的书名列表。 元数据包括
ItemClass、Itemkey、ItemPublicationyear和itemcegory
。书名是 以以下格式返回:

booktitle {itemclass,itemkey,itempublicationyear,[itemcategory]} 
//ItemCategory can have mult. values
正则表达式形式的过滤器应用于{}内的元数据,以将正确的标题返回给用户

书籍标题的示例列表如下所示:

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]}
用户请求可以由一个或多个筛选器组成。 例如 用户可以请求属于itemclasses 102、33168的书籍标题列表,以便正则表达式 像这样:

(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筛选器进行预订,以便用户可以请求 除项目键为32647326的书籍外的所有书籍标题

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+)*)\]

你想要的最终结果没有得到正确的解释?
以上每个输入都是字符串吗

“{16838162012[04,14]}”
“{168380872012[14,32]}”
“{168379552012[14,32]}”
“{168334092011[14]}”
你能回答以下问题吗?
你到底想匹配什么?
是否要检查第一个逗号后的第一个数字是否不等于33409?
“我希望我的正则表达式能够排除多个数字”=>这里的多个数字是什么意思?

但是,根据我的理解,请尝试以下reg ex

/{\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]}

这些数字最终将如何解析?