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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:21:25+00:00 2026-05-23T07:21:25+00:00

I’m trying to build a parser that would be able to extract the data

  • 0

I’m trying to build a parser that would be able to extract the data using regex.

I want to be able to match

Here is what I have right now:

(\w+)\s+('|")([^\2\\]*(\\.[^\2\\]*)*)\2\s*;

The ([^\2\\]*(\\.[^\2\\]*)*) part was taken from http://ad.hominem.org/log/2005/05/quoted_strings.php

Unfortunately I have two problems with this pattern.

First of all, I would like to be able to capture string which aren’t enclosed with single/double quotes.

Having print "hello world"; works but print foobar; doesnt’t work. I haven’t been able to make the backreference \2 optional at the end.

Furthermore, I don’t know if it’s just the way I enclosed the regex, but I can’t seem to be able to parse multiple instance of this pattern.

If i try the regex with print 'hello'; print 'foobar';, it would just return the first print 'hello'; part.

Thanks in advance for your help.

Edit

Here is a snippet of what I’m trying to parse:

listen          80;
server_name     domain.com *.domain.com;
rewrite ^       http://www.domain.com$request_uri? permanent;

I am trying to capture every action with their parameters. Basically I wan’t to be able to parse the NGINX configuration file: http://wiki.nginx.org/FullExample

  • 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-23T07:21:25+00:00Added an answer on May 23, 2026 at 7:21 am

    A backreference doesn’t work in a character class [^\2] like that. It might be a multi-character string, and cannot be used there. You could work around that using a ((?!\2).)* construct. But it would really be simpler if you just simplified your match pattern.

    The easiest approach here would be to list the three possible alternatives separately:

     /(\w+)\s+ (?: '([^']*)' |  "([^"]*)" | (\S+) ) \s*;/x
    

    Obviously you would then have to fetch the results from the result sets [2], [3] or [4] manually.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to create an if statement in PHP that prevents a single post
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put

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.