Regex match strings between asterisks

依然范特西╮ 提交于 2021-02-05 09:48:10

问题


I have a string like this:

var s = "*string1* *string2* *string3*";

I'm trying to create a regex which returns an array of the three strings between *

How can I do that? I tried using this but I'm not sure if it is correctly escaped

s.match("\*(.*)\*")

Thanks


回答1:


You need to use lazy quantifier ? here and also escape \

Like this \*(.*?)\* Regex101 Demo

Without using lazy quantifier you can do something like this.

\*[^*]+\* This will match a * everything until a * *. Regex101 Demo

Use \\ instead of \ in actual code.



来源:https://stackoverflow.com/questions/36635582/regex-match-strings-between-asterisks

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!