Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试在用户输入时进行更改
color*red
用户想在里面搜索:
the color is red the color is blue
我更改*为(\W|\w|\s)*在 Django 过滤内的正则表达式中使用它。
*
(\W|\w|\s)*
NameItem=NameItem.replace("*","(\W|\w|\s)*") ItemsSelected=Items.objects.filter(Name__iregex=NameItem)
但它从来没有给我结果。
任何的想法?
你忘了制作"(\W|\w|\s)*"一个原始字符串。另一方面,我不知道您为什么使用它而不是".*".
"(\W|\w|\s)*"
".*"