# Are the regular expressions same?

## Recommended Posts

Hi,

I have got following regular expression:

(bba U aab)*

Is this similar to:

(bba)* U (aab)*

I think they are same, please guide me.

Zulfi.

##### Share on other sites

I believe that you are refering to logic, if this is the case then you may be attempting to replicate de Morgan's theorum. In which case you are very close. What made you believe that this expression that you came up with is correct. May you missed a small step somewhere in your logic.

##### Share on other sites

(text) creates "capturing group", which can be referenced during replacing by e.g. $1,$2 etc. (or other following digit)

Use one of many on-line regular expressions debuggers, if you have any objections. Like this one for example:

##### Share on other sites
2 hours ago, zak100 said:

(bba U aab)*

The first regular expression gets at least one match in any input string, since the whole pattern is optional due to the placement of the star "*". It has one capturing group.

2 hours ago, zak100 said:

(bba)* U (aab)*

The second regular expression requires the string " U " (Capital U surrounded by spaces) to occur once while the two patterns "bba" and "aab" are optional

This regular expression has two capturing groups.

2 hours ago, zak100 said:

I think they are same, please guide me.

Why do you think they are the same? It is easier to guide if you give some hint about your reasoning.

Example:
First regular expression matches for instance the whole string:
"bba U aabbba U aab"
(The second regular expression matches the initial substring "bba U aab")

The second regular expression matches for instance the whole string:
"bbabbabba U aabaabaab"

Edited by Ghideon

##### Share on other sites

Hi,

Thanks for your response. Sorry ALine this is automata theory.

Ghideon: Please tell me what you ean by one and two capturing groups?

Sensei: Please give mme some example how the online debugger can help me to differentiate?

(bba U aab)*= bba, aab, aab, bba ... or empty

Can't  we not have bbabbaabaab in the above regular expression?

(bba)* U (aab)* = bba, bbabba, bbabbabba, empty, aab, aabaab

Zulfi.

##### Share on other sites
30 minutes ago, zak100 said:

Ghideon: Please tell me what you ean by one and two capturing groups?

Sorry, I thought you were familiar with regular expressions. I'll explain later

31 minutes ago, zak100 said:

(bba U aab)*= bba, aab, aab, bba ... or empty

Can't  we not have bbabbaabaab in the above regular expression?

(bba)* U (aab)* = bba, bbabba, bbabbabba, empty, aab, aabaab

You seem to assume that the cheater "U" has some special meaning. That is not correct. See my first post.

##### Share on other sites
1 hour ago, zak100 said:

(bba U aab)*= bba, aab, aab, bba ... or empty

Can't  we not have bbabbaabaab in the above regular expression?

(bba)* U (aab)* = bba, bbabba, bbabbabba, empty, aab, aabaab

Zulfi.

I want to say it should be:

(bba)* ∩ (aab)*

Just to be clear I'm assuming by 'U' you mean Union and by '*' negation.

##### Share on other sites
43 minutes ago, Endy0816 said:

I want to say it should be:

(bba)* ∩ (aab)*

Just to be clear I'm assuming by 'U' you mean Union and by '*' negation.

Good point!

Also points at the issues with the opening question. In regular expression union is represented by "|", it's not represented by the charter "U".

@zak100 Maybe you could clarify if actually wish to discuss regular expressions* or something else? Its not obvious if you try to solve an issue with programming syntax or have a more general issue with sets, logic or similar. Also, just a friendly reminder; we are on a discussion forum, your short questions "please tell me", "please give examples" etc does not, in my opinion, promote fruitful discussions. They are more suitable for entering into a search engine for a quick and precise answer.

Edited by Ghideon

##### Share on other sites

Hi,

"Maybe you could clarify if actually wish to discuss regular expressions* or something else? "

I am discussing about regular expressions. Its not programming/logic, its automata theory course.

In my opening post "U" means the union, its same as "+" and I am talking about regular expression. "*" means zero or more repititions. I don't know about negative.

"Also, just a friendly reminder; we are on a discussion forum, your short questions "please tell me", "please give examples" etc does not, in my opinion, promote fruitful discussions."

Whatever information, I have I used to provide, i.e. code, images and expressions. If you need more information please let me know.

Zulfi.

##### Share on other sites
13 minutes ago, zak100 said:

In my opening post "U" means the union,

No, in regular expressions it does NOT mean union....

You mixed two different independent things. Regular expressions with mathematics (set theory)..

On 10/15/2020 at 6:27 AM, zak100 said:

Sensei: Please give mme some example how the online debugger can help me to differentiate?

If you would enter a sample regular expression with a sample text string into the online debugger, you should see that it doesn't work as you think.

Edited by Sensei

##### Share on other sites
38 minutes ago, zak100 said:

I am discussing about regular expressions. Its not programming/logic, its automata theory course.

Ok. Then we can drop the examples and start from the basic.

43 minutes ago, zak100 said:

In my opening post "U" means the union, its same as "+" and I am talking about regular expression.

45 minutes ago, zak100 said:

Whatever information, I have I used to provide, i.e. code, images and expressions. If you need more information please let me know.

For instance what kind of regular expression you use. There are different variants with different syntax. If you want to use your own personal syntax you need to tell us all the rules you have invented.

##### Share on other sites

Hi,

I am following the syntax of our teacher and he says that "U" is for union and it is same as "+" or logical "or" operator. I don't know what you mean by union. Sorry for not specifying this earlier.

Please tell me what you guys mean by "U" in the context of regular expression?

Sensei: I would try the calculator and then let you know.

Zulfi.

Edited by zak100

##### Share on other sites
1 hour ago, zak100 said:

I am following the syntax of our teacher and he says that "U" is for union and it is same as "+" or logical "or" operator. I don't know what you mean by union. Sorry for not specifying this earlier.

Can you show us a reference where the teacher tells what kind of regular expression they use? Are you sure they actually discuss regular expression?

1 hour ago, zak100 said:

Please tell me what you guys mean by "U" in the context of regular expression?

It is a character. The regular expression U has a match in the text ”Us” but there is no match in the text ”Bar”

In other words, there is nothing special about U.

Edited by Ghideon

##### Share on other sites
On 10/16/2020 at 3:29 PM, zak100 said:

I am following the syntax of our teacher and he says that "U" is for union and it is same as "+" or logical "or" operator.

Simply, it is not true.

Regular expression has some special characters with special meanings. "U" is not one of them. It is normal letter from point of view of regex.

"In the regex flavors discussed in this tutorial, there are 12 characters with special meanings: the backslash \, the caret ^, the dollar sign \$, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ),  (....)"

##### Share on other sites
21 minutes ago, Sensei said:

Simply, it is not true.

I agree.

Good list of special characters. Just an additional note @zak100

On 10/16/2020 at 7:47 AM, Ghideon said:

There are different variants with different syntax

You never told us what you or your teacher uses so you need to be aware that in some cases the escaping differs among regular expression styles. Some platforms use backslash to escape parenthesis: $$regexp$$.

##### Share on other sites
On 10/19/2020 at 1:05 PM, Ghideon said:

Some platforms use backslash to escape parenthesis: regexp

I missed that the forum handles backlash + parenthesis specially. I meant:

$$regexp$$

## Create an account

Register a new account