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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:41:21+00:00 2026-06-15T02:41:21+00:00

In a file is apparently stored a multiline regex, saved by YAML::dump(b1) without a

  • 0

In a file is apparently stored a multiline regex, saved by YAML::dump(b1) without a problem.

Question, how can I load it back when Syck seems to have issues with the multiline regular expression?

b2 = YAML::load(File.open("browserObj.yaml", 'r'))

Syck::TypeError: Invalid Regular expression: "/\\A\\s*\n        ([a-zA-Z][\\-+.a-zA-Z\\d]*):                           (?# 1: scheme)\n        (?:\n           ((?:[\\-_.!~*'()a-zA-Z\\d;?:@&=+$,]|%[a-fA-F\\d]{2})(?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*) \\                   (?# 2: opaque)\n        |\n           (?:(?:\n             \\/\\/(?:\n \\                (?:(?:((?:[\\-_.!~*'()a-zA-Z\\d;:&=+$,]|%[a-fA-F\\d]{2})*)@)? \\       (?# 3: userinfo)\n                   (?:((?:(?:[a-zA-Z0-9\\-.]|%\\h\\h)+|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\[(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})|(?:(?:[a-fA-F\\d]{1,4}:)*[a-fA-F\\d]{1,4})?::(?:(?:[a-fA-F\\d]{1,4}:)*(?:[a-fA-F\\d]{1,4}|\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}))?)\\]))(?::(\\d*))?))? (?# 4: host, 5: port)\n               |\n                 ((?:[\\-_.!~*'()a-zA-Z\\d$,;:@&=+]|%[a-fA-F\\d]{2})+) \\                (?# 6: registry)\n               )\n             |\n             (?!\\/\\/)) \\                          (?# XXX: '\\/\\/' is the mark for hostport)\n \\            (\\/(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*(?:;(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*)*(?:\\/(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*(?:;(?:[\\-_.!~*'()a-zA-Z\\d:@&=+$,]|%[a-fA-F\\d]{2})*)*)*)? \\                   (?# 7: path)\n           )(?:\\?((?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*))? \\                (?# 8: query)\n        )\n        (?:\\#((?:[\\-_.!~*'()a-zA-Z\\d;\\/?:@&=+$,\\[\\]]|%[a-fA-F\\d]{2})*))? \\                 (?# 9: fragment)\n      \\s*\\z/x"
    from /usr/lib/ruby/1.9.1/syck/rubytypes.rb:284:in `yaml_new'
    from /usr/lib/ruby/1.9.1/syck.rb:135:in `transfer'
    from /usr/lib/ruby/1.9.1/syck.rb:135:in `node_import'
    from /usr/lib/ruby/1.9.1/syck.rb:135:in `load'
    from /usr/lib/ruby/1.9.1/syck.rb:135:in `load'
    from /usr/lib/ruby/1.9.1/syck.rb:146:in `block in load_file'
    from /usr/lib/ruby/1.9.1/syck.rb:145:in `open'
    from /usr/lib/ruby/1.9.1/syck.rb:145:in `load_file'
    from (irb):428
    from /usr/bin/irb:12:in `<main>'

I’ve seen discussion about a patch to rubytypes.rb but otherwise nothing.

I’d rather not switch to Psych since that opens up another can of worms:

YAML::ENGINE.yamler = "psych"

# attempt to load from file again
TypeError: can't convert Fixnum into String

What’s going on? Is there any hope? I had no prior knowledge of Syck nor Psych nor the internals of YAML parsing until this error made it non-transparent.

  • 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-15T02:41:23+00:00Added an answer on June 15, 2026 at 2:41 am

    You could store the regexp as string. When you read it back from the yaml file just convert the string back into a regexp. Regexp.new myregexp_str – This is of course just a workaround.

    Update:
    Or you could do something that really stupid and patch psych to handle multiline regexp.
    Since the patched method is to long to post it grab it here.
    But here is the explanation of what was really patched.

    module Psych
      module Visitors
        class ToRuby < Psych::Visitors::Visitor
           # ...
          def deserialize
            # ... L75
            when "!ruby/regexp"
            o.value =~ /^\/(.*)\/([mixn]*)$/m # <- notice the added "m" for multiline mode
            # ...
          end
        end
      end
    end
    

    using ruby-1.9.3-p194

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

Sidebar

Related Questions

The following causes a bug because file.eof() apparently doesn't return true until a read
How can I read multiple lines from a text file (variable width) and store
I want to display a 480x320 JPEG file stored in the SD card in
I'm trying to load some data from a plist file. It contains an NSArray
I have a PKCS#5 encrypted PKCS#8 RSA private key stored in a disk file
EDIT: Apparently, the problem is in the read function: I checked the data in
Apparently I was asking the wrong question in my earlier post. I have a
In my Android app, I load a file and a folder containing a bunch
file://localhost/C:/Users/kürşat/Desktop/yeni%20site/faq%20-%20Kopya/kopya.html this is my photography tutorial page. I'm did manage to toggle on/off when
FILE: I'm working with a refined csv version of a searchlog file which contains

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.