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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:45:00+00:00 2026-06-06T06:45:00+00:00

My string delimiter is ; . Delimiter is escaped in the string as \;

  • 0

My string delimiter is ;. Delimiter is escaped in the string as \;. E.g.,

irb(main):018:0> s = "a;b;;d\\;e"
=> "a;b;;d\\;e"
irb(main):019:0> s.split(';')
=> ["a", "b", "", "d\\", "e"]

Could someone suggest me regex so the output of split would be ["a", "b", "", "d\\;e"]? I’m using Ruby 1.8.7

  • 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-06T06:45:03+00:00Added an answer on June 6, 2026 at 6:45 am

    1.8.7 doesn’t have negative lookbehind without Oniguruma (which may be compiled in).

    1.9.3; yay:

    > s = "a;b;c\\;d"
    => "a;b;c\\;d"
    > s.split /(?<!\\);/
    => ["a", "b", "c\\;d"]
    

    1.8.7 with Oniguruma doesn’t offer a trivial split, but you can get match offsets and pull apart the substrings that way. I assume there’s a better way to do this I’m not remembering:

    > require 'oniguruma'
    > re = Oniguruma::ORegexp.new "(?<!\\\\);"
    > s = "hello;there\\;nope;yestho"
    > re.match_all s
    => [#<MatchData ";">, #<MatchData ";">]
    > mds = re.match_all s
    => [#<MatchData ";">, #<MatchData ";">]
    > mds.collect {|md| md.offset}
    => [[5, 6], [17, 18]]
    

    Other options include:

    • Splitting on ; and post-processing the results looking for trailing \\, or
    • Do a char-by-char loop and maintain some simple state and just split manually.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Split string by delimiter, but not if it is escaped I have
I'd like to String.Split() the following string using a comma as the delimitter: John,Smith,123
String SomeLongString = JavaAPIMethodFor (String[] strings, String delimiter); Or this could work as well:
How can I split a string by a delimiter, but not if it is
I've used the following split function: CREATE FUNCTION dbo.Splitfn(@String varchar(8000), @Delimiter char(1)) returns @temptable
Possible Duplicate: Split string based on delimiter in bash? i have a shell script
I would like to use regex to look inside a string for the smallest
Im having trouble reading from a CSV file final String DELIMITER = ,; Scanner
for (Entry<String, String> entry : map.entrySet()) { String delimiter = **; result = result.replace(delimiter
I have a string : NSString *s = @a+v+c+d; Where '+' is the delimiter.

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.