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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:24:28+00:00 2026-05-24T01:24:28+00:00

I have a file of data fields, which may contain comments, like below: id,

  • 0

I have a file of data fields, which may contain comments, like below:

id, data, data, data
101 a, b, c
102 d, e, f
103 g, h, i // has to do with 101 a, b, c
104 j, k, l
//105 m, n, o
// 106 p, q, r

As you can see in the first comment above, there are direct references to a matching pattern. Now, I want to capture 103 and it’s three data fields, but I don’t want to capture what’s in the comments.

I’ve tried negative lookbehind to exclude 105 and 106, but I can’t come up with a regex to capture both.

(?<!//)(\b\d+\b),\s(data),\s(data),\s(data)

This will capture all but exclude capture of 105, but to specify

(?<!//\s*) or (?<!//.*)

as my attempt to exclude a comment with any whitespace or any characters invalidates my entire regex.

I have a feeling I need a crafty use of an anchor, or I need to wrap what I want in a capture group and make a reference to it (like with $1) in my lookbehind.


If this is another case of “regular expressions don’t support recursion” because it’s a regular language (a la automata theory), please point that out.

Is it possible to exclude the comments in 103, and lines 105 and 106, using a regular expression? If so, how?

  • 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-24T01:24:30+00:00Added an answer on May 24, 2026 at 1:24 am

    The easy way out is to replace \s*//.* with the empty string before you begin.

    This will remove all the (single-line) comments from your input and you can go on with a simple expression to match what actually you want.

    The alternative would be to use look-ahead instead of look-behind:

    ^(?!//)(\b\d+\b),\s(data),\s(data),\s(data)
    

    In your case it would even work to just anchor the regex because it is clear that the first thing on a line must be a digit:

    ^(\b\d+\b),\s(data),\s(data),\s(data)
    

    Some regex engines (the one in .NET, for example), support variable-length look-behinds, your’s does not seem to be capable of this, this is why (?<!//\s*) fails for you.

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

Sidebar

Related Questions

I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have an Excel file (which has data imported from Oracle 10G Database) one
I have an .sql file which contains some data like first_name, last_name, email etc.
I have a text file containing data/fields which are separated by exact column no.
I have a data file that looks like the following example. I've added '%'
I have a CSV data file with rows that may have lots of columns
I have a NetCDF file, which contains data representing total precipitation across the globe
I have a csv data set containing a date field which my may or
I have a csv file into which has crept some ^M dos line ends,
I have a file with data listed as follows: 0, 2, 10 10, 8,

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.