正则表达式替换多次出现的字符,留下一个空白
我想在solr中实现通配符查询。我希望当我搜索 query= ****diamond
时,它应该搜索whiltediamond 等。即所有 '*'
都应该替换为 ''
(空白)除了 1 *
即。它应该作为 *diamond
运行,我正在使用
query=query.replace(/[^a-zA-Z 0-9 * ? : .]+/g,'');
它意味着除了 *
、?
、:
、.
它将所有特殊字符替换为 ''。现在我想对其进行转换,因为它应该替换所有 *
,留下一个 *
为 ''
。 比什么应该是正则表达式。
I want to implement wild card query in solr. I want that when I search for query= ****diamond
, it should search for whiltediamond etc. ie all '*'
should be replaced by ''
(blank) except 1 *
ie. it should run as *diamond
, I am using
query=query.replace(/[^a-zA-Z 0-9 * ? : .]+/g,'');
It means other than *
, ?
, :
, .
it is replacing all special characters by a ''. now i want to convert it as that it should replace all *
leaving one *
by ''
.
Than what should be regular expression.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的正则表达式应执行以下操作:
仅用一个星号替换任意数量的星号:
Your regex should do the following:
Replace any number of asterisks by only one asterisk: