Search code examples
regexxregexp

RegEx - get only last asterisk


Is it possible to do a RegEx to only match the last asterisk right before and first asterisk right after an value?

Value: **example**

My actual regex: /\*(.*?)\*/g

My actual regex matches the two asterisks before and after word example, but i want to do a regex that only matches the last asterisk right before and the first asterisk right after the word.

Thank you!


Solution

  • try /[*][^*]+[*]/gm

    Works as tested on regex101.com