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: ,

841 questions
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
14
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
  • 253
  • 1
  • 5
8
votes
1 answer

Equivalence of regular expressions

Is it possible, in general, to determine whether two regular expressions admit the same set of strings? Also, in particular, is it possible to determine whether a given regular expression admits the same set of strings as the regular expression ".*"…
Paul Reiners
  • 243
  • 1
  • 2
  • 5
6
votes
2 answers

Why are regular expression quantifiers greedy by default?

I can't count the number of times I've seen questions on StackOverflow related to regular expressions where the problem was due to the programmer not understanding the impact of greedy quantifiers. Most recently, Python regex issue — [\S\s]* vs…
Barmar
  • 443
  • 2
  • 8
4
votes
4 answers

how did they get this answer for the words that don't have bba and abb?

I am looking at the answer in solution manual which asked , all the words that don't have both substring bba and abb. and the answer was a*(baa*)*b+b*(a*ab)*a* and I'm like wait a minute is that right ? but that can't make abb, which is in the…
Dana
  • 355
  • 2
  • 5
  • 13
4
votes
1 answer

Regular expression for words containing single 1 and even number of 0s

What would be a regular expression for the language of words containing a single 1 and an even number of 0s?
user97862
  • 41
  • 1
4
votes
1 answer

Finding simpler equivalent regular expressions

I'm doing an exercise from my book that says: Let $r$ and $s$ be arbitrary regular expressions over the alphabet $\Sigma$. Find a simpler equivalent regular expression: a. $r(r^*r + r^*) + r^*$ b. $(r + \Lambda)^*$ c. $(r + s)^*rs(r + s)^* +…
badjr
  • 325
  • 5
  • 14
3
votes
1 answer

Simplying this regular expression

I am trying to prove (without converting it into Automata, through just simplification) that the following two regular expressions are equal: $ (\epsilon + 0^*1^+0)^* = \epsilon + (0+1)^*10 $ here is what I have got so far: $$ (\epsilon + 0^*1^+0)^*…
Gravity
  • 185
  • 5
3
votes
2 answers

Length of a regular expression

What is the definition for the length of a regular expression? This question might sound simple, yet I cannot find a definition. Do I only count letters from the alphabet? Do * and $\cup$ count? For example: let r = $(ab)^*\cup$ $a$. What is $|r|$?
3
votes
3 answers

Regular Expression with at least one a, even number of b

I've been working on some regular expression questions, and came across one that I cannot figure out. Working on the language over $\{a, b\}$, the text asks for a regular expression for the language of all words having at least one a and an even…
Ari
  • 31
  • 1
  • 3
3
votes
1 answer

Regular expressions with cycles

A knob is used to select one of three positions A, B, C. The knob can never be turned from A to C, or from C to A, without spending at least one second in position B. The initial position of the knob can be any of A, B, C. Give a regular expression…
Perplexityy
  • 133
  • 3
3
votes
2 answers

Interpretation of this regular expression: (1*0*)*

Do the values of the two * inside the ( ) need to remain unchanged for every repetition of ( )? For example, 110011001100 is part of this language set, but 1100100010 isn't? Or can the values of the two * change for every repetition of the ( )?
Shukie
  • 41
  • 1
2
votes
1 answer

I need to present a regular expression for the following languages:

1. L2 = E{0,1) All the words in L2 with equal number of 0's and 1's and every prex of w has at most two more of either 0's or 1's. 2. All words that does not contain “bbb” as substring. i think this is :( e + b + bb)(a + ab + abb)* Thanks in…
user14988
2
votes
2 answers

Which of the following regular expressions generate(s) no string with two consecutive 1’s?

This is a GRE practice question. Which of the following regular expressions generate(s) no string with two consecutive 1’s? (Note that ε denotes the empty string.) I. (1 + ε)(01 + 0)* II. (01+10)* III. (0+1)*(0+ε) (A) I only (B) II only (C) III…
Tootsie Rolls
  • 233
  • 3
  • 4
  • 7
2
votes
1 answer

Regular expression for language with even number of 0's and 1's

Let $\Sigma=\{0,1\}$. What is the regular expression for the language of all strings with an even number of $0$'s and an even number of $1$'s? If we only require an even number of $0$'s, the language $(1^*)\mid(1^*01^*01^*)^*$ works. But once there…
mba
  • 375
  • 1
  • 2
  • 6
1
2 3 4 5 6