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

  • SEARCH
  • Home
  • 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 7935693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:00:08+00:00 2026-06-03T22:00:08+00:00

Is there a simpler way to write the following regular expression, specifically avoiding all

  • 0

Is there a simpler way to write the following regular expression, specifically avoiding all the groupings with the ‘?’ optional character?

/^w(o(r(d)?)?)?$/

It should match the following:

  • w
  • wo
  • wor
  • word

and should not match, as mere examples:

  • wr
  • wd
  • woo
  • wrr
  • wodr
  • wrdo
  • ord
  • rd
  • odr

In this particular case its a very short word but you can see by this next example how things can become ugly very fast.

Regex to match vertical or horizontal and any amount of first sequential characters of each word:

/^h(o(r(i(z(o(n(t(a(l)?)?)?)?)?)?)?)?)?|v(e(r(t(i(c(a(l)?)?)?)?)?)?)?)$/

I’m using ruby but I think this question applies to any language that makes use of regular expressions, so I’ll thank answers in any language. Don’t know much about perl, though…

I only found one question similar to mine but doesn’t show any better solution, anyway, here is the link.

  • 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-06-03T22:00:10+00:00Added an answer on June 3, 2026 at 10:00 pm

    You could simplify it with an OR expression:

    /^(w|wo|wor|word)$/
    

    or reverse the test by making a regex from the input text (in pseudo code):

    "word" matches /input + ".*"/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a simpler way to write the following query (to see if any
Is there a simpler way to rewrite the following condition in JavaScript? if ((x
Is there a more concise and idiomatic way to write the following code, which
Is there a simpler way of implement this? Or a implemented method in JDK
Is there a simpler way to get a string of a parent directory than
Given two lists of equal length, is there a simpler or preferred way to
When I write a regular expression like: var m = /(s+).*?(l)[^l]*?(o+)/.exec(this is hello to
I'm wondering if there is a way to write MIPS assembly language file (just
I had to write a method that does the following: There is a DataSet
Is there a simple way to do async in Perl? I have the following

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.