Questions tagged [regular-expressions]

Regular expressions or Regex is a search pattern for strings defined by a sequence of characters.

A regular expression (shortened as regex or regexp) is a sequence of characters that specifies a search pattern. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations on strings, or for input validation. It is a technique developed in theoretical computer science and formal language theory. The phrase regular expressions, or regexes, is often used to mean the specific, standard textual syntax for representing patterns for matching text, as distinct from the mathematical notation described below. Each character in a regular expression (that is, each character in the string describing its pattern) is either a metacharacter, having a special meaning, or a regular character that has a literal meaning.

681 questions
15
votes
1 answer

Automata | Prove that if $L$ is regular than $half(L)$ is regular too

I've see couple of approaches to this kind of questions yet I have no clue how to approach this one. Let L be regular language, and let $half(L)$ be: $half(L) = \{u \mid uv \in L\ s.t. |u|=|v|\}$. Prove that if $L$ is regular then $half(L)$ is…
Aviad
  • 253
9
votes
1 answer

Is the set of regular languages closed under set difference?

Let $\Sigma$ be an alphabet and $L_1,L_2 \subseteq \Sigma^*$ two regular languages. I know that $REG$ is closed under intersections of regular languages and under complementation of a regular language. My reasoning looks like this: $L_1 \setminus…
8
votes
2 answers

Express y in terms of x

Question: $$ \text{It is given that } y= \frac{3a+2}{2a-4} \text{and }x= \frac{a+3}{a+8} \\ $$ $$ \text{Express } y \text{ in terms of } x. $$ From using $x$ to solve for $a$, I discovered that $$ a = \frac{8x-3}{1-x} $$ Then I proceeded to…
8
votes
0 answers

What is the probability that a random regular expression defines the language of all binary strings $\{0, 1\}^*$?

Suppose we generate a random regular expression $R$ in the following way: We start with a single meta-symbol $S$. Then each turn we independently replace all $S$ in our word with $\{0\}$, $\{1\}$, $(S \cup S)$, $SS$ or $S^*$ with equal probability.…
8
votes
2 answers

Proving that all equivalent regular expressions are reachable via algebraic laws

Given a set of laws for regular expressions, for example (ripped from this document): $$ \begin{array}{llll} \text{1.} & (A|B)|C = A|(B|C) &\qquad& \text{(associativity of choice)}\\ \text{2.} & (AB)C = A(BC) && \text{(associativity of…
7
votes
2 answers

How can concatenating empty sets (languages) result in a set containing empty string?

In the book "Introduction to the Theory of Computation" by Michael Sipser, in the section 1.3 Regular Expressions: The symbol ε represents the emty string, which may be a valid element of a language: L = {ε}. The symbol ∅ represents an empty set; a…
user1713188
  • 71
  • 1
  • 1
  • 2
7
votes
1 answer

Freshening up on discrete math (regular expressions)

I'm trying to freshen myself up on discrete math( I forgot a lot). I know this is a trivial question and not worth your time. But I forgot how to solve problems involving formal language theory. For example lets say you were trying to (a) write a…
7
votes
1 answer

Is one regular language subset of another?

Let $L_1$ and $L_2$ be two regular languages given as regular expressions (in this type of tasks it often happens that $L_1 \subseteq L_2$, but vice versa it is false). Is there a nice way to prove that $L_1 \subseteq L_2$ ? If yes, than do you…
6
votes
1 answer

Complement of a regular expression?

What is the regex for the complement of $r = b^*(ab + a^* + abb(b^+))^*$ ? I am thinking $(a+b)^*(abb)^+a^* $ since anything that contains $abb$ and is not followed by $b$'s would not be accepted by $r$. Would this be correct?
6
votes
1 answer

How to write a regular expression?

I am trying to write a regular expression for the set of all strings in $\Sigma^*$ that starts with an even number of $b$'s and contains at most two $a$'s. The language contains only $a$'s and $b$'s. This is what I have figured out so far: $b^*$ -…
Sarah
  • 263
5
votes
2 answers

Function from natural to lexicographically ordered words of a-z

I think I am looking for a very basic lexicographic ordering concept/function/algorithm, but I'm stumped. Basically, it has to produce the following mapping: f(0) = a f(1) = b ... f(25) = z f(26) = aa f(27) = ab ... f(??) = zz f(??) = aaa I think…
5
votes
4 answers

How does one show that these two expressions are the same?

I tried to compute the value of $\sin 75^\circ$ using the sine of standard values $(30^\circ, 45^\circ...)$ and did it by two ways. One, by expanding $\sin (45^\circ+30^\circ)$ and the other by computing the half of $\sin 150^\circ$ using basic…
Alraxite
  • 5,767
5
votes
1 answer

Finding the set of strings over $\{a, b\}$ that do not contain the substring aaa

I need to identify the set of all possible strings over $\Sigma = \{a, b\}$ that do not contain the substring $aaa$. I have becoming more familiar with regular-language and languages explored in Automata Theory, and have been defining a…
5
votes
0 answers

Solving the equation X = AX + B of languages for X

I'm currently working on the following problem for my computer theory class. It goes as follows: Let $A$ and $B$ be regular expressions. Show then that $A^* B$ is the solution of $X = AX + B$. Am I supposed to let $X = A^*B$? If so then $$A^* B…
trungnt
  • 231
5
votes
3 answers

Number of sequences that contain a given "run"

Consider sequences of numbers 0, 1, 2 with length n. There are $3^n$ such sequences. I want to know how many sequences there are that contain a k-run of 1's followed by 2. As a regular expression: (^|.*[^1])[1]{k}[2].* Even better would be to…
1
2 3
45 46