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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T20:56:38+00:00 2026-05-14T20:56:38+00:00

I apologize for the terrible title…it can be hard to try to summarize an

  • 0

I apologize for the terrible title…it can be hard to try to summarize an entire situation into a single sentence.

Let me start by saying that I’m asking because I’m just not a Regex expert. I’ve used it a bit here and there, but I just come up short with the correct way to meet the following requirements.

The Regex that I’m attempting to write is for use in an XML schema for input validation, and used elsewhere in Javascript for the same purpose.

There are two different possible formats that are supported. There is a literal string, which must be surrounded by quotation marks, and a Hex-value string which must be surrounded by braces.

Some test cases:

"this is a literal string" <– Valid string, enclosed properly in “s
"this should " still be correct" <– Valid string, “s are allowed within (if possible, this requirement could be forgiven if necessary)
"{00 11 22}" <– Valid string, {}’s allow in strings. Another one that can be forgiven if necessary
I am bad output <– Invalid string, no "s
"Some more problemss"you know <– Invalid string, must be fully contained in "s
{0A 68 4F 89 AC D2} <– Valid string, hex characters enclosed in {}s
{DDFF1234} <– Valid string, spaces are ignored for Hex strings
DEADBEEF <– Invalid string, must be contained in either "s or {}s
{0A 12 ZZ} <– Invalid string, ‘Z’ is not a valid Hex character

To satisfy these general requirements, I had come up with the following Regex that seems to work well enough. I’m still fairly new to Regex, so there could be a huge hole here that I’m missing.:

&quot;.+&quot;|\{([0-9]|[a-f]|[A-F]| )+\}

If I recall correctly, the XML Schema regex automatically assumes beginning and end of line (^ and $ respectively). So, essentially, this regex accepts any string that starts and ends with a ", or starts and ends with {}s and contains only valid Hexidecimal characters. This has worked well for me so far except that I had forgotten about another (although less common, and thus forgotten) input option that completely breaks my regex.

Where I made my mistake:
Valid input should also allow a user to separate valid strings (of either type, literal/hex) by a comma. This means that a single string should be able to contain more than one of the above valid strings, separated by commas. Luckily, however, a comma is not a supported character within a literal string (although I see that my existing regex does not care about commas).

Example test cases:
"some string",{0A F1} <– Valid
{1122},{face},"peanut butter" <– Valid
{0D 0A FF FE},"string",{FF FFAC19 85} <– Valid (Spaces don’t matter in Hex values)
"Validation is allowed to break, if a comma is found not separating values",{0d 0a} <– Invalid, comma is a delimiter, but “Validation is allowed to break” and “if a comma…” are not marked as separate strings with "s
hi mom,"hello" <– Invalid, String1 was not enclosed properly in "s or {}s

My thoughts are that it is possible to use commas as a delimiter to check each “section” of the string to match a regex similar to the original, but I just am not that advanced in regex yet to come up with a solution on my own. Any help would be appreciated, but ultimately a final solution with an explanation would just stellar.

Thanks for reading this huge wall of text!

  • 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-14T20:56:38+00:00Added an answer on May 14, 2026 at 8:56 pm

    According to http://www.regular-expressions.info/xml.html the regex language to be used in XSD is less expressive than the one used in Java, but expressive enough for your task.

    Now for a construction, take your own regex. Replace the dot with a negated character class [^,] to match everything except the comma, and (for increased clarity) merge the hexadecimal character classes into one. You get the following regex:

    &quot;[^,]+&quot;|\{[0-9a-fA-F ]+\}
    

    If we name this regex <S> (for “single string”), the additional feature is validated by the regex matching any number of <S>,, followed by a single <S>:

    (<S>,)*<S>
    

    Expanded, this yields the desired regex:

    ((&quot;[^,]+&quot;|\{[0-9a-fA-F ]+\}),)*(&quot;[^,]+&quot;|\{[0-9a-fA-F ]+\})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize that the title may not make sense, so let me describe my
I apologize for this seemingly relatively simple task that I can't figure out. I
I apologize for the title.. i couldn't find a better way to explain the
I apologize if this question was already asked but I can't seem to find
I apologize for the wordy title - I wasn't sure how to phrase this
Apologies for the terrible title, not really sure how to explain this without a
I apologize in advance, I'm not sure what category this question fits into, if
I apologize for asking such a generalized question, but it's something that can prove
I apologize for any confusion from the question title. It's kind of a complex
Apologies for the terrible title, I wasn't quite sure how to phrase my problem.

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.