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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:50:02+00:00 2026-06-15T01:50:02+00:00

Using Ruby 1.9.2, I have the following Ruby code in IRB: > r1 =

  • 0

Using Ruby 1.9.2, I have the following Ruby code in IRB:

> r1 = /^(?=.*[\d])(?=.*[\W]).{8,20}$/i
> r2 = /^(?=.*\d)(?=.*\W).{8,20}$/i
> a = ["password", "1password", "password1", "pass1word", "password 1"]
> a.each {|p| puts "r1: #{r1.match(p) ? "+" : "-"} \"#{p}\"".ljust(25) + "r2: #{r2.match(p) ? "+" : "-"} \"#{p}\""}

This results in the following output:

r1: - "password"         r2: - "password"
r1: + "1password"        r2: - "1password"
r1: + "password1"        r2: - "password1"
r1: + "pass1word"        r2: - "pass1word"
r1: + "password 1"       r2: + "password 1"

1.) Why do the results differ?

2.) Why would r1 match on strings 2, 3 and 4? Wouldn’t the (?=.*[\W]) lookahead cause it to fail since there aren’t any non-word characters in those examples?

  • 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-15T01:50:03+00:00Added an answer on June 15, 2026 at 1:50 am

    This results from the interaction between a couple of regex features and Unicode. \W is all non-word characters, which includes 212A – “KELVIN SIGN” K (PDF link) and 017F – “LATIN SMALL LETTER LONG S” ſ (PDF link). The /i adds lower case versions of both of these, which are the “normal” k and s characters (006B – “LATIN SMALL LETTER K” and 0073 “LATIN SMALL LETTER S” (PDF link)).

    So it’s the s in password that’s being interpreted as a non-word character in certain cases.

    Note that this only seems to occur when the \W is in a character class (i.e. [\W]). Also I can only reproduce this in irb, inside a standalone script it seems to work as expected.

    See the Ruby bug about this for more information.

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

Sidebar

Related Questions

Using Rails 3.2.0.rc2 and ruby 1.9.3p0 In app/views/requests/_form.html.erb I have the following code for
Using Ruby 1.9.2, Rails 3.1. I have the following code: # review.rb def calculate_rating(reviewable)
I am using Ruby on Rails v3.0.9 and I have the following code in
I have gotten the following errors using ruby 1.9.2-p320 with Heroku's Taps-using 'db' commands
I have the following expression: ^\w(\s(+|-|/|*)\s\w)*$ This simply looks to match a mathematical expression,
I am using Ruby 1.8.6 for the following code: # Create an array and
I am using Ruby 1.9.2 and Ruby on Rails 3.2.2. I have following statements:
I am using Ruby on Rails 3.2.2. I have the following scenario: # hash_params.class
I have the following Ruby code: require 'rubygems' require 'rest_client' url = 'http://asdf.com' response
I have the following code: Dir.chdir(mydir) Dir.entries(mydir).each do |file| log.info(file) end My problem is

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.