Regular Expressions

Concentric

Expert Member
Joined
Feb 16, 2017
Messages
1,028
Reaction score
197
If i need to create a regular expression for a language L that contains the letters {a,b} that if it contains the sub-string bb, it can only contain it once.Am i correct in saying that no string in L can contain more than 2 b's together.
Wouldn't bbb result in 2 sub-strings of bb: (bb)b and b(bb) and therefore not be allowed.

Thanks
@cguy hope you dont mind the ping :sneaky:
 
Just so we're on the same page here:

* You have some string, say `bbb`.
* You're trying to find out whether a regular expression containing two b's would return two matches or not?

Well that depends on the settings of the engine you're using (or if I understand that you're creating).

Supplying the regex of `bb` against the string `bbb` results in the first two b's being matched and the 3rd b being ignored when I use the _pcre_ engine.
 
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

OK, enough about my work email sig and answering your question :) ... It depends on your engine but you would use look ahead / look around to determine if it is 2 and not 3 b's.

https://www.regular-expressions.info/lookaround.html

Which language are you using and which engine?
 
Image1535412267.739901.jpg

Use to have this at work..

I actually like regular expressions and if you really want to feel pain do it in bash scripts to fix file naming conventions by finding, sorting + rename. Ah the good ole telecoms game of gazillion telecoms record files..
 
Top
Sign up to the MyBroadband newsletter
X