Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:30:24+00:00 2026-05-16T20:30:24+00:00

One of my homework questions asked to develop a regex for all strings over

  • 0

One of my homework questions asked to develop a regex for all strings over x,y,z that did not contain xxx

After doing some reading I found out about negative lookahead and made this which works great:

(x(?!xx)|y|z)*

Still, in the spirit of completeness, is there anyway to write this without negative lookahead?

Reading I have done makes me think it can be done with some combination of carets (^), but I cannot get the right combination so I am not sure.

Taking it a step further, is it possible to exclude a string like xxx using only the or (|) operator, but still check the strings in a recursive fashion?

EDIT 9/6/2010:

Think I answered my own question. I messed with this some more, trying make this regex with only or (|) statements and I am pretty sure I figured it out… and it isn’t nearly as messy as I thought it would be. If someone else has time to verify this with a human eye I would appreciate it.

(xxy|xxz|xy|xz|y|z)*(xxy|xxz|xx|xy|xz|x|y|z)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:30:24+00:00Added an answer on May 16, 2026 at 8:30 pm

    Try this:

    ^(x{0,2}(y|z|$))*$
    

    The basic idea is this: for match at most 2 X’s, followed by another letter or the end of the string.

    When you reach a point where you have 3 X’s, the regex has no rule that allows it to keep matching, and it fails.

    Working example: http://rubular.com/r/ePH0fHlZxL

    A less compact way to write the same is (with free spaces, usually the /x flag):

    ^(
    y|         # y is ok
    z|         # so is z
    x(y|z|$)|  # a single x, not followed by x
    xx(y|z|$)  # 2 x's, not followed by x
    )*$
    

    Based on the latest edit, here’s an ever flatter version of the pattern: I’m not entirely sure I understand your fascination with the pipe, but you can eliminate some more options – by allowing an empty match on the second group you don’t need to repeat permutations from the first group. That regex also allows ε, which I think is included in your language.

    ^(xxy|xxz|xy|xz|y|z)*(xx|x|)$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not a homework problem. This questions was asked to one of my
One of my homework questions is to search using grep an lines that contain
this one is not homework, it just the fact that i've been out of
This is homework, and this questions Extends this one So there is a button
I'm working on a homework assignment (a project), for which one criterion is that
The questions I have are NOT homework questions, but I am considering using these
I need some help with one of the questions from my homework, Ive been
This is one of the boring academic OOP questions, but it is not a
This is the questions, i admit this is a homework questions, i am not
Okay one of my homework problems is to take a list of lists and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.