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 1011947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:52:12+00:00 2026-05-16T09:52:12+00:00

Following on from this question I asked yesterday: Can I shorten this regular expression?

  • 0

Following on from this question I asked yesterday:

Can I shorten this regular expression?

The solution was to use the following expression:

^([a-z]{5}-){4}[a-z]{5}$ 

To check for a match for a string with the following format:

aBcDe-fghIj-KLmno-pQRsT-uVWxy

I was advised to omit the A-Z from my original query and make the Regular Expression case insensitive in the code that uses it. For example, specify RegExOptions.IgnoreCase in the constructor for the RegEx in C#.

Is there any reason why this should be done in code rather than the regular expression itself?

I think this question is valid enough to warrant a new question rather than continuing the discussion in yesterday’s.

  • 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-16T09:52:13+00:00Added an answer on May 16, 2026 at 9:52 am

    There is no absolutely correct answer to this question. There are several ways to achieve certain things, and which is best is sometimes subjective. Besides, the two ways aren’t exactly identical to begin with.

    It should be noted that a regex pattern can in fact be partially case-insensitive. That is, you can have a pattern that is case insensitive in one part, but case sensitive in other parts.

    Perhaps a good guideline is the following:

    • The case-insensitivity flag can be used to indicate that (barring embedded modifiers that override the setting) the entire pattern matching process is case-insensitive
    • If case-insensitivity doesn’t apply to the entire pattern matching process, you may choose to dismiss the flag and just make it explicit that certain parts are

    Do note that there is in fact a big difference between these two patterns:

    /([a-z]+)-\1/i
    /([A-Za-z]+)-\1/
    

    Both patterns match "FOO-FOO" and "bar-bar", but the first pattern matches "BOO-boo" (as seen on rubular.com). The second pattern does not (as seen on rubular.com).

    See also

    • regular-expressions.info/Modifiers
      • Specifying Modes Inside The Regular Expression
        • Instead of /regex/i (Pattern.CASE_INSENSITIVE in Java), you can do /(?i)regex/
      • Turning Modes On and Off for Only Part of The Regular Expression
        • You can also do /first(?i)second(?-i)third/
      • Modifier Spans
        • You can also do /first(?i:second)third/

    Related questions

    • Case sensitive and insensitive in the same pattern
    • Can you make just part of a regex case-insensitive?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.