Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'two-level regular expressions' mean?

Tags:

regex

I understand basic regular expression, but unsure what the below quote means (regarding how to implement a wiki parser), could anyone provide some pseudo code to enlighten me?

Two-level regular expressions

This is a very popular approach. It's pretty fast, as it scans the raw text exactly two times.

The idea is to create two kinds of regular expressions -- one to split the text into blocks of different kinds (paragraphs, headings, lists, preformatted blocks, etc.) and then process each of them with different character-level regular expression.

Quote from: http://www.wikicreole.org/wiki/CommonWikiParsingTechniques

like image 768
user1154337 Avatar asked Feb 22 '23 19:02

user1154337


1 Answers

It means not trying to accomplish multiple tasks in a single Regex, but to split it into two tasks (two levels); splitting first, then handling each token separately.

My opinion is that people often unecessarily try to have a single Regex do too much at once, instead of making things much simpler by splitting different tasks like this.

like image 139
Andrew Barber Avatar answered Mar 02 '23 22:03

Andrew Barber