问题
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