Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex string between a double asterisk

Tags:

regex

I have the following string:

What is **Sympathy.**

I'm attempting to create a regex statement that will find the string "Sympathy." between the double asterisk, including the double asterisk. However, I can't even figure out how to find the string between first.

This is what I've tried:

(?<=\\*\\*)(.*)(?=\\*\\*)

Any assistance would be appreciated.

like image 943
CodeLikeBeaker Avatar asked Jan 06 '23 07:01

CodeLikeBeaker


1 Answers

I tested this out and it worked

\*{2}(.*?)\*{2}

Breakdown

\*{2}- matches the character * literally (exactly 2 times)

1st Capturing group (.*?) - The quantifier will match it between 0 and unlimited times

\*{2}- matches the character * literally (exactly 2 times)

https://regex101.com/r/uQ0gJ1/1

like image 106
Richard Hamilton Avatar answered Jan 18 '23 19:01

Richard Hamilton