Questions tagged [regular-expressions]

Questions about regular expressions, a formalism to describe regular languages.

Questions about regular expressions, a formalism to describe regular languages.

If you are asking about how to find a regular expression for some language, please consult How do I find a regular expression for a particular language? before asking, and show what progress you have made.

Note that regular expressions in a computer science context are not the same as POSIX RegExp or similar. A regular expression in the formal language sense $R$ can be one of

  • the empty language $\emptyset$,
  • the empty string $\varepsilon$ (also $\lambda$),
  • an individual symbol $a \in \Sigma$ with $\Sigma$ some finite alphabet,
  • a concatenation $R_1 \cdot R_2$,
  • an alternative $(R_1 \mid R_2)$ (often $+$ is used) and
  • a Kleene star $(R_1)^*$.

See the corresponding Wikipedia article for details.

Related: ,

862 questions
146
votes
5 answers

How to convert finite automata to regular expressions?

Converting regular expressions into (minimal) NFA that accept the same language is easy with standard algorithms, e.g. Thompson's algorithm. The other direction seems to be more tedious, though, and sometimes the resulting expressions are…
34
votes
4 answers

How to simulate backreferences, lookaheads, and lookbehinds in finite state automata?

I created a simple regular expression lexer and parser to take a regular expression and generate its parse tree. Creating a non-deterministic finite state automaton from this parse tree is relatively simple for basic regular expressions. However I…
Aadit M Shah
  • 465
  • 4
  • 8
32
votes
13 answers

Unusual applications of regular expressions?

I am looking for some interesting applications of regular expressions. Can you name any unusual, or unobvious, cases where regexes find their application?
weno
  • 445
  • 4
  • 4
31
votes
1 answer

Is regex golf NP-Complete?

As seen in this recent XKCD strip and this recent blog post from Peter Norvig (and a Slashdot story featuring the latter), "regex golf" (which might better be called the regular expression separation problem) is the puzzle of defining the shortest…
29
votes
3 answers

Which languages do Perl-compatible regular expressions recognize?

As the title says, I spent a couple of hours last weekend trying to wrap up my mind about the class of languages matched by Perl-compatible regular expressions, excluding any matching operator that allows to execute arbitrary code inside the…
peppe
  • 549
  • 4
  • 9
27
votes
1 answer

"Dense" regular expressions generate $\Sigma^*$?

Here's a conjecture for regular expressions: For regular expression $R$, let the length $|R|$ be the number of symbols in it, ignoring parentheses and operators. E.g. $|0 \cup 1| = |(0 \cup 1)^*| = 2$ Conjecture: If $|R| > 1$ and $L(R)$ contains…
26
votes
6 answers

What is the Relationship Between Programming Languages, Regular Expressions and Formal Languages

I've looked around the net for an answer to this question and it seems as if everybody implicitly knows the answer except me. Presumably this is because the only people who care are those who have had tertiary education on the subject. I, on the…
20
votes
1 answer

Regular expressions with backreferences over unary alphabet

Setting: regular expressions with backreferences unary language (1-symbol alphabet) Is the following problem decidable in this setting: Given a regular expression with backreferences, does it define a regular language? For example, (aa+)\1…
18
votes
2 answers

For every 'evil' regex, does there exist a non-evil alternative, or is the devil in the grammar?

Apparently, ReDos attacks exploit characteristics of some (otherwise useful) regular expressions ... essentially causing an explosion of possible paths through the graph defined by the NFA. Is it possible to avoid such problems by writing an…
David Bullock
  • 281
  • 1
  • 3
17
votes
2 answers

Are regular expressions $LR(k)$?

If I have a Type 3 Grammar, it can be represented on a pushdown automaton (without doing any operation on the stack) so I can represent regular expressions by using context free languages. But can I know if a type 3 grammar is $LR(1)$, $LL(1)$,…
15
votes
1 answer

Can POSIX BRE express all regular languages?

It appears that "Basic Regular Expressions" as defined by POSIX.1-2008 do not support alternation, a|b (although some grep implementations recognize the escaped version, \|). Since the regular languages are closed under union by definition, does…
Steve Kobes
  • 153
  • 5
15
votes
1 answer

When is a regexp not a Regular Expression?

Since I'm studying for my formal languages college course, I stumbled upon these fascinating posts (One Two) which describe how to find a prime number using a regexp. As I said, a regexp, not a regular expression. Since a regular expression can…
peperunas
  • 263
  • 1
  • 5
15
votes
3 answers

Why is the Kleene star operator also called the Kleene 'closure' operator?

I've found that if I don't understand the etymology behind a cs/programming term, it usually means that I've missed or misunderstood some important underlying concept. I don't understand why the Kleene star is also called the Kleene closure. Is it…
mallardz
  • 253
  • 1
  • 2
  • 5
15
votes
2 answers

Does the language of Regular Expressions need a push down automata to parse it?

I want to convert a user entered regular expression into an NFA so that I can then run the NFA against a string for matching purposes. What is the minimum machine that can be used to parse regular expresssions? I assume it must be a push down…
14
votes
1 answer

Difference between regular expression and grammar in automata

I am new to automata, and I have been given a brief introduction to regular expressions only yesterday. I have read the various rules which to define a regular expression. But I am unable to differentiate between regular expressions and grammar of a…
Charu Bansal
  • 143
  • 1
  • 1
  • 8
1
2 3
57 58