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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:56:12+00:00 2026-05-28T04:56:12+00:00

Suppose I have a text file with some data I want to retrieve lost

  • 0

Suppose I have a text file with some data I want to retrieve lost in a sea of regular written language.
Each piece of data I want to retrieve is a tuple of 3 numbers between 0 and 99 (that I will call N1 to N3), which can be formatted in 4 different ways:

  • N1-N2-N3
  • N1N2N3
  • N1.N2.N3
  • N1/N2/N3

Using regular expressions, is it possible to describe something like that:
Something I will call separator later is something in this list : [ '-', '', '.', '/' ]
My expression is like: N1{separator}N2{same_separator_as_the_first_one}N3
?

It seems like the only way to express that is:
My expression is like: ({N1}-{N2}-{N3}) OR ({N1}{N2}{N3}) OR ({N1}.{N2}.{N3}) OR ({N1}/{N2}/{N3})

…which becomes quickly unreadable…

Is it possible to achieve the first kind of expression with regular expressions? Is there something available which is not regex that allows this kind of expressiveness?

The real question is:

Given the available formats, what is the best way to write a function
which gets a string and returns N1 to N3 along with the used separator
character (and throws an exception when the string does not match any
format)?

  • 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-28T04:56:13+00:00Added an answer on May 28, 2026 at 4:56 am

    This depends slightly on the flavor of regex, but in a typical language, I would write:

    ([1-9]?[0-9])([-./]?)([1-9]?[0-9])\2([1-9]?[0-9])
    

    Then group 2 is the separator, and groups 1, 3, and 4 are the three numbers.

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

Sidebar

Related Questions

Suppose I have a text file with data separated by whitespace into columns. I
Suppose I have 500 rows of data, each with a paragraph of text (like
Suppose I have a regular expression (a)|(b)|(c)|(d) . If I apply it to text
my app is supposed to store some data in a text file. Every time
I want to slice word from the end.Suppose, I have some line with case
I run across this problem frequently suppose I have a text file that I
Suppose I have a file which contains other file names with some extention [.dat,.sum
Suppose you have a text file like: my_setting = ON some_method = METHOD_A verbosity
Suppose I have a .csv file with the following content: text, with commas,another text,123,text,5;
Suppose I have a text that I can easily parse. It consists of 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.