Kawamoto Takeshi
Kawamoto Takeshi

Reputation: 606

RegEx that finds multiple lines that have same starting and ending pattern

I keep seeing solutions for Regexes that find lines/words with a start and end pattern but the difference is their patterns are different.

My dilemma is finding lines that have the same ending and start pattern.

Example:

** Hello, My name is
Name: enter**

That would result to one match. However when I do

Example:

 **Hello, My name is
 Name: enter**
 **Designation is:
 Field work**

The match result should be two, but catches three, which are:

 **Hello, My name is
 Name: enter**

And:

             **
**

And:

**Designation is:
Field work**

I'm using this Regex:

"^##.*##"

Someone said it is not possible using Regex, is this true?

Upvotes: 1

Views: 382

Answers (3)

Ahosan Karim Asik
Ahosan Karim Asik

Reputation: 3299

Try this: /\*\*(.+?)\*\*/s

\*\* #match the first ** 
(.+?) # match any char btween ** and **  and group 
\*\*  #match the last ** 
s  #single line modifier.

Live demo

VB demo

Upvotes: 1

Jacques Ramsden
Jacques Ramsden

Reputation: 871

Try the following Regex

(\*\*(.*?)\\*\*\*)

Upvotes: 0

vks
vks

Reputation: 67968

(\*\*[\s\S]*?\*\*)

Try this.See demo.

https://regex101.com/r/tX2bH4/12

Upvotes: 0

Related Questions