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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:15:35+00:00 2026-05-17T03:15:35+00:00

I’m not very well versed with regular expressions. I’ve had to use them, maybe

  • 0

I’m not very well versed with regular expressions. I’ve had to use them, maybe once every few years, and that was mostly for course work. Anyways, the following question should be a fairly straight forward question/answer for anyone familiar with regular expressions.

I need to ensure that the text entered into a field follows the following format:

x y z

or

x,y,z

or

x y z / <same pattern can repeat for almost unlimited length>

or

x,y,z / <...> // Spaces after the comma are ok

where x, y and z can only be integers. The patterns cannot be intermixed, so you cannot have

x, y, z / x y z / ...

I’ve tried the following

([1-9] [1-9] [1-9])

to get the x y z part, but I don’t know how to include the ‘/’ nor the ‘,’

Any suggestions?

  • 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-17T03:15:35+00:00Added an answer on May 17, 2026 at 3:15 am

    I guess you can use

    Regex r = new Regex("^([0-9]+([ ,]|, )[0-9]+(\\2)[0-9]+)( [/] ([0-9]+(\\2)[0-9]+(\\2)[0-9]+)+)*$");
    
    var x1 = r.IsMatch("1,2 3");         // false
    var x2 = r.IsMatch("1 3 2 / 1 2 3"); // true
    var x3 = r.IsMatch("1,3,2");         // true
    var x4 = r.IsMatch("1 3 2 / 1");     // false
    
    Console.WriteLine((x1 == false) ? "Correct" : "Error");
    Console.WriteLine((x2 == true) ? "Correct" : "Error");
    Console.WriteLine((x3 == true) ? "Correct" : "Error");
    Console.WriteLine((x4 == false) ? "Correct" : "Error");
    Console.ReadLine();
    

    Spliting in smaller pieces

    [0-9]+  matches any number, even 0. If it can't start with 0
            you will have to change it
    [ ,]    the separator allows a space or a comma
    \\2     matches the same thing the second group matched (space or comma)
    

    The second big parenthesis matches or not more iterations of this sequence if started by /.

    If all separator needs to be exactly the same, replace them by \\2 (just don’t replace the first, that is what it is going to match for the group 2).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text

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.