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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:57:22+00:00 2026-05-13T18:57:22+00:00

I’m using a commercial application that has an option to use RegEx to validate

  • 0

I’m using a commercial application that has an option to use RegEx to validate field formatting. Normally this works quite well. However, today I’m faced with validating the following strings: quoted alphanumeric codes with simple arithmetic operators (+-/*). Apparently the issue is sometimes users add additional spaces (e.g. “ FLR01” instead of “FLR01”) or have other typos such as mismatched parenthesis that cause issues with downstream processing.

The first examples all had 5 codes being added:

“FLR01″+”FLR02″+”FLR03″+”FMD01″+”FMR05”

So I started going down the road of matching 5 alphanumeric characters quoted by strings:

“[0-9a-zA-Z]{5}”[+-*/]

However, the formulas quickly got harder and I don’t know how to get around the following complications:

  1. I need to test for one of the four simple math operators (+-*/) between each code, but not after the last one.
  2. There can be any number of codes being added together, not just five as in the example above.
  3. Enclosed parenthesis are okay (“X”+”Y”)/”2”
  4. Mismatched parenthesis are not okay.
  5. No formula (e.g. a blank) is okay.

Valid:

"FLR01"+"FLR02"+"FLR03"+"FMD01"+"FMR05"
"0XT"+"1SEAL"+"1XT"+"23LSL"+"23NBL"  
("LS400"+"LT400")*"LC430"/("EL414"+"EL414R"+"LC407"+"LC407R"+"LC410"+"LC410R"+"LC420"+"LC420R")

Invalid:

" FLR01" +"FLR02"
"FLR01"J"FLR02"
("FLR01"+"FLR02"

Is this not something you can easily do with RegExp? Based on Jeff’s answer to 230517, I suspect I’m failing at least the ‘matched pairing’ issue. Even a partial solution to the problem (e.g. flagging extra spaces, invalid operators) would likely be better than nothing, even if I can’t solve the parenthesis issue. Suggestions welcomed!

Thanks,

Stephen

  • 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-13T18:57:23+00:00Added an answer on May 13, 2026 at 6:57 pm

    As you are aware you can’t check for matching parentheses with regular expressions. You need something more powerful since regexes have no way of remembering state and counting the nested parentheses.

    This is a simple enough syntax that you could hand code a simple parser which counts the parentheses, incrementing and decrementing a counter as it goes. You’d simply have to make sure the counter never goes negative.

    As for the rest, how about this?

    ("[0-9a-zA-Z]+"([+\-*/]"[0-9a-zA-Z]+")*)?
    

    You could also use this regular expression to check the parentheses. It wouldn’t verify that they’re nested properly but it would verify that the open and close parentheses show up in the right places. Add in the counter described above and you’d have a proper validator.

    (\(*"[0-9a-zA-Z]+"\)*([+\-*/]\(*"[0-9a-zA-Z]+"\)*)*)?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a distributed application framework (commercial is okay as well) that supports iPhone
I'm working on some code that compiles and links (and even has released commercial
My software encodes videos using the standard Windows AVIFile functionality. That means, it can
We have a commercial software product under development. It supports Oracle, MySQL, and SQL*Server
I'm developing a C#/.NET application (Winforms/WPF, not entirely decided yet) which needs to display
I have built a multi-touch application which is based on a Java EE backend
I have managed to setup a blog on localhost quickly using wordpress. But what
In the D2 programming language, what are the performance implications of using exception handling?
I have an Object Inspector, just like Delphi's, which I show at run-time to
I make a lot of simple single executable applications for various things at home

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.