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的(非常允许的)(.+)
。也许他的身份证钥匙上有连字符?