Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 查找具有_id的字符串并排除值_Javascript_Regex - Fatal编程技术网

Javascript 查找具有_id的字符串并排除值

Javascript 查找具有_id的字符串并排除值,javascript,regex,Javascript,Regex,我有以下用于查找类的正则表达式: about_class = about_key.match(/^(.+)_id$/)[1] 上述表达式将与用户id、联系人id等匹配 我想排除字符串作者id 如何更新表达式以排除作者id /^(?!author_id$)(\w+)_id$/ > "foo_id".match(/^(?!author_id$)(\w+)_id$/) ["foo_id", "foo"] > "author_id".match(/^(?!author_id$)(\w+)

我有以下用于查找类的正则表达式:

about_class = about_key.match(/^(.+)_id$/)[1]
上述表达式将与
用户id
联系人id
等匹配

我想排除字符串
作者id


如何更新表达式以排除
作者id

/^(?!author_id$)(\w+)_id$/

> "foo_id".match(/^(?!author_id$)(\w+)_id$/)
["foo_id", "foo"]
> "author_id".match(/^(?!author_id$)(\w+)_id$/)
null

second\u author\u id
这样的东西怎么样?我感觉到一个XY问题。你想手工解析JSON之类的标准格式吗?不过我还是会保留OP的(非常允许的)
(.+)
。也许他的身份证钥匙上有连字符?