← All stories
● Covered by 1 source · 1 reportLow impact1 neutral

Understanding Regular Expressions and Formal Language Theory

🔄 Updated 1d ago
New to BrevFeed? We gather this story from every outlet covering it into one summary — ranked by real-world impact, not just the latest headline — so you never miss what matters. What is BrevFeed? →

Key points

  • Formal language theory defines "regular" based on specific grammar production rules.
  • Regular expressions offer a concise way to represent regular grammars.
  • The grammar for natural numbers is a regular grammar.
  • Regular expressions are powerful for tasks within their scope.

The Misconception of Regular Expressions

A common statement in programming discussions, particularly regarding HTML parsing, is that "You cannot parse HTML with regular expressions, because HTML isn’t regular." This article addresses this statement, arguing it is often misleading or incorrect in the context of specific parsing needs. It aims to demonstrate the capabilities of modern regular expressions.

Defining "Regular" in Formal Language Theory

In formal language theory, a language is considered "regular" if its grammar adheres to specific production rules. These rules are B -> a, B -> aC, or B -> ε. Here, 'B' and 'C' represent non-terminals (symbols that can be further broken down), and 'a' represents a terminal (a symbol that cannot be broken down further), while 'ε' denotes an empty string.

Example: Natural Numbers as a Regular Grammar

The article provides an example using the grammar for natural numbers to illustrate a regular grammar. This grammar defines a natural number (N) as either a digit from 0 to 9, or a digit from 0 to 9 followed by another natural number. This structure fits the criteria for a regular grammar, with digits acting as terminals and 'N' as the non-terminal.

Regular Expressions for Conciseness

While the grammar for natural numbers is regular, its formal definition can be verbose. Regular expressions offer a more concise way to express such grammars. The example grammar for natural numbers is equivalent to the regular expression [0-9]+, which is significantly simpler and more compact.

✨ This summary was generated by AI from the outlets' reporting listed below. It is not independently verified and may contain errors — check the original sources. How BrevFeed works →

The daily brief

One email each morning: the day's tech stories, clustered across outlets and summarized. No account needed.

One email a day. Unsubscribe in one click, any time.

Today's brief

Spend a few minutes, get the whole day. Every topic's top stories in one hands-free rundown — listen, watch, or read the transcript.

~7 min · 6 stories · Aug 15

▶ Play today's brief Listen on Spotify

New every morning, and the back catalogue is archived by date.

Reporting from

This article clarifies the definition of "regular" in the context of formal language theory and demonstrates how modern regular expressions can concisely represent regular grammars. It explains that while HTML is not a regular language, regular expressions are powerful tools for specific parsing tasks.