Regex match strings between asterisks

后端 未结 1 1473
小鲜肉
小鲜肉 2021-01-28 05:37

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

相关标签:
1条回答
  • 2021-01-28 06:23

    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.

    0 讨论(0)
提交回复
热议问题