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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:54:12+00:00 2026-05-11T13:54:12+00:00

As stated in the title, is there a way, using regular expressions, to match

  • 0

As stated in the title, is there a way, using regular expressions, to match a text pattern for text that appears outside of quotes. Ideally, given the following examples, I would want to be able to match the comma that is outside of the quotes, but not the one in the quotes.

This is some text, followed by ‘text, in quotes!’

or

This is some text, followed by ‘text, in quotes’ with more ‘text, in quotes!’

Additionally, it would be nice if the expression would respect nested quotes as in the following example. However, if this is technically not feasible with regular expressions then it wold simply be nice to know if that is the case.

The programmer looked up from his desk, ‘This can’t be good,’ he exclaimed, ‘the system is saying ‘File not found!”

I have found some expressions for matching something that would be in the quotes, but nothing quite for something outside of the quotes.

  • 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. 2026-05-11T13:54:13+00:00Added an answer on May 11, 2026 at 1:54 pm

    This can be done with modern regexes due to the massive number of hacks to regex engines that exist, but let me be the one to post the ‘Don’t Do This With Regular Expressions’ answer.

    This is not a job for regular expressions. This is a job for a full-blown parser. As an example of something you can’t do with (classical) regular expressions, consider this:

    ()(())(()()) 

    No (classical) regex can determine if those parenthesis are matched properly, but doing so without a regex is trivial:

    /* C code */  char string[] = '()(())(()())'; int parens = 0; for(char *tmp = string; tmp; tmp++) {   if(*tmp == '(') parens++;   if(*tmp == ')') parens--; } if(parens > 0) {   printf('%s too many open parenthesis.\n', parens); } else if(parens < 0) {   printf('%s too many closing parenthesis.\n', -parens); } else {   printf('Parenthesis match!\n'); }  # Perl code  my $string = '()(())(()())'; my $parens = 0; for(split(//, $string)) {   $parens++ if $_ eq '(';   $parens-- if $_ eq ')'; } die 'Too many open parenthesis.\n' if $parens > 0; die 'Too many closing parenthesis.\n' if $parens < 0; print 'Parenthesis match!'; 

    See how simple it was to write some non-regex code to do the job for you?

    EDIT: Okay, back from seeing Adventureland. 🙂 Try this (written in Perl, commented to help you understand what I’m doing if you don’t know Perl):

    # split $string into a list, split on the double quote character my @temp = split(/'/, $string);  # iterate through a list of the number of elements in our list for(0 .. $#temp) {    # skip odd-numbered elements - only process $list[0], $list[2], etc.   # the reason is that, if we split on 's, every other element is a string   next if $_ & 1;    if($temp[$_] =~ /regex/) {     # do stuff   }  } 

    Another way to do it:

    my $bool = 0; my $str; my $match;  # loop through the characters of a string for(split(//, $string)) {    if($_ eq ''') {     $bool = !$bool;     if($bool) {        # regex time!       $match += $str =~ /regex/;        $str = '';     }   }    if(!$bool) {      # add the current character to our test string     $str .= $_;   } }  # get trailing string match $match += $str =~ /regex/; 

    (I give two because, in another language, one solution may be easier to implement than the other, not just because There’s More Than One Way To Do It™.)

    Of course, as your problems grow in complexity, there will arise certain benefits of constructing a full-blown parser, but that’s a different horse. For now, this will suffice.

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

Sidebar

Related Questions

as the title states, I am trying to query multiple mySQL tables in the
I'm trying to figure out what the best way would be to set up
Ok the title is not clear, here is what I mean. I am programming
A common way I handle things in Drupal is to create a CCK type,
I'm trying to generate a Google Map based off of results from a database.
I've just started developing a hobby site for myself, and trying to use the
I've started the development of a windows application, which target windows 7 and vista
I am used to post my ideas on one forum and started to worry
So today I started learning ASP.NET. Unfortunately I haven't found any good tutorials online,
Did anybody know more information about this attack ? I recently got this script

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.