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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:17:05+00:00 2026-06-07T20:17:05+00:00

I have a string like this: a b c a b a b b

  • 0

I have a string like this:

a b c a b ” a b ” b a ” a “

How do I match every a that is not part of a string delimited by "? I want to match everything that is bold here:

a bc a b ” ab ” b a ” a “

I want to replace those matches (or rather remove them by replacing them with an empty string), so removing the quoted parts for matching won’t work, because I want those to remain in the string. I’m using Ruby.

  • 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-07T20:17:06+00:00Added an answer on June 7, 2026 at 8:17 pm

    Assuming the quotes are correctly balanced and there are no escaped quotes, then it’s easy:

    result = subject.gsub(/a(?=(?:[^"]*"[^"]*")*[^"]*\Z)/, '')
    

    This replaces all the as with the empty string if and only if there is an even number of quotes ahead of the matched a.

    Explanation:

    a        # Match a
    (?=      # only if it's followed by...
     (?:     # ...the following:
      [^"]*" #  any number of non-quotes, followed by one quote
      [^"]*" #  the same again, ensuring an even number
     )*      # any number of times (0, 2, 4 etc. quotes)
     [^"]*   # followed by only non-quotes until
     \Z      # the end of the string.
    )        # End of lookahead assertion
    

    If you can have escaped quotes within quotes (a "length: 2\""), it’s still possible but will be more complicated:

    result = subject.gsub(/a(?=(?:(?:\\.|[^"\\])*"(?:\\.|[^"\\])*")*(?:\\.|[^"\\])*\Z)/, '')
    

    This is in essence the same regex as above, only substituting (?:\\.|[^"\\]) for [^"]:

    (?:     # Match either...
     \\.    # an escaped character
    |       # or
     [^"\\] # any character except backslash or quote
    )       # End of alternation
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have a string like this in C#: string a = A|B|C|D I want
I have string like this : <input name=my_name id=my_id value=my_value class=my_class /> I would
I have string like this: G:\Projects\TestApp\TestWeb\Files\Upload\file.jpg How can I remove all text before Files
I have a string like this: matrix(10, 0, 1, 0, -198, 23) Then I
I have a string like this one: 1.1 Apoyar en la planeación y realización
i have a string like this one: $string = some text http://dvz.local/index/index/regionId/28 http://stuff.kiev.ua/roadmap_page.php http://192.168.3.192/roadmap_page.php
i have a string like this one $sitesinfo = 'site 1 titles-example1.com/ site 2
I have a string like this /blog/post1/ how can i get the post1 from
I have a string like this: String A: [ 12234_1_Hello'World_34433_22acb_4554344_accCC44 ] I would like

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.