![](/img/trans.png)
[英]regular expression to remove all tags with content and html code from a string
[英]Regular expression to skip all <html> tags and search in remaining text
我正在使用MongoDB,我有一个名为Companies的集合,它的文件如下 -
{
"_id":1,
"name": "Innovative Software pvt. limited 1",
"description": "This is a software company"
}
{
"_id":2,
"name": "Innovative Software pvt. limited 2",
"description": "This is a software,company with <img src='' class='' alt='company logo' /> symbol"
}
{
"_id":3,
"name": "Innovative Software pvt. limited 3",
"description": "This is a software, company with <img src='' class='' alt='company,logo' /> symbol"
}
{
"_id":4,
"name": "Innovative Software pvt. limited 4",
"description": "This is a software, company with,<img src='' class='' alt='company, logo' /> symbol"
}
现在我想要一个正则表达式来找到所有那些decsription字段满足以下条件的公司 -
1-逗号与其后面的字母/数字/图像之间没有空格。
2-它不应该在img标签中包含内容写入。
所以在我的情况下,我想要以下文件的输出 -
_id:2(“描述”:“这是一个软件,与......有关,
_id:4(“描述”:“这是一个软件,公司机智,< ..
我想要一个类似的查询 -
db.Companies.find({description:{$regex:'regular expression'}})
它可以在查询本身中实现,或者我需要在代码本身内部编写逻辑。 我正在使用pymongo。
试试这个正则表达式:
/"description"\s*:\s*"(?:[^<'"]|\\")+?,(?=[<a-z]).+"/gi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.