Regex for a string between two characters, but not three of that character

I am parsing a document and would like to split it using php preg_split ().

The document consists of sections with headings:

==Section Title==

The problem is that each section has subsections with headers:

===Subsection Title===

Question: Is there a way to use regular expression for analysis through a document for things that are between two equal characters, but not between three equal characters?

Thank!

PS I'm trying to learn regex, but I still find it pretty confusing!

+5
source share
3 answers

Here you need to work:

(?<!=)==(?!=)(.*)(?<!=)==(?!=)

How it works:

(?<!=)==(?!=) ( ). , (?<!=) ( lookbehind) (?!=) ( lookahead). , , , ===.

(.*) ==.

+6

, WikiCreole, WikiCreole PHP.

http://wiki.wikicreole.org/Libraries

+3

Assuming there is no space at the beginning and end of the line:

^==[^=]+==$
+1
source

All Articles