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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:08:30+00:00 2026-06-02T03:08:30+00:00

I am reading information out of a formatted string. The format looks like this:

  • 0

I am reading information out of a formatted string.
The format looks like this:

"foo:bar:beer:123::lol"

Everything between the “:” is data I want to extract with regex. If a : is followed by another : (like “::”) the data for this has to be “” (an empty string).

Currently I am parsing it with this regex:

(.*?)(:|$)

Now it came to my mind that “:” may exist within the data, as well. So it has to be escaped.
Example:

"foo:bar:beer:\::1337"

How can I change my regular expression so that it matches the “\:” as data, too?

Edit: I am using JavaScript as programming language. It seems to have some limitations regarding complex regulat expressions. The solution should work in JavaScript, as well.

Thanks,
McFarlane

  • 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-06-02T03:08:31+00:00Added an answer on June 2, 2026 at 3:08 am
    var myregexp = /((?:\\.|[^\\:])*)(?::|$)/g;
    var match = myregexp.exec(subject);
    while (match != null) {
        for (var i = 0; i < match.length; i++) {
            // Add match[1] to the list of matches
        }
        match = myregexp.exec(subject);
    }
    

    Input: "foo:bar:beer:\\:::1337"

    Output: ["foo", "bar", "beer", "\\:", "", "1337", ""]

    You’ll always get an empty string as the last match. This is unavoidable given the requirement that you also want empty strings to match between delimiters (and the lack of lookbehind assertions in JavaScript).

    Explanation:

    (          # Match and capture:
     (?:       # Either match...
      \\.      # an escaped character
     |         # or
      [^\\:]   # any character except backslash or colon
     )*        # zero or more times
    )          # End of capturing group
    (?::|$)    # Match (but don't capture) a colon or end-of-string
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently looking to process and parse out information from this .txt file
I'm hitting the user limit of freebase while reading out information. It certainly has
I'm working on reading and writing information in HecDSS. I had this script working
Out of curiosity/excitement I have been reading whatever information I can find about ARC
Been reading/searching but can't seem to figure out how to do this without having
Reading package lists... Done Building dependency tree Reading state information... Done The following package
Java is reading the locale, timezone and encoding information (and perhaps more) from the
I'm reading Thinking in C++ (vol. 2): Whenever a function is called, information about
Reading this question I found this as (note the quotation marks) code to solve
Reading over the responses to this question Disadvantages of Test Driven Development? I got

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.