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

  • Home
  • SEARCH
  • 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 7733991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:08:19+00:00 2026-06-01T07:08:19+00:00

I’m new to Ruby, Regex and Stackoverflow. xD Here’s my problem: I want to

  • 0

I’m new to Ruby, Regex and Stackoverflow. xD Here’s my problem:

I want to use regex to extract phrases consisting of consecutive words with standard ASCII characters apart from the others in Vietnamese texts.

In another word, phrases with \w characters only, for example:

Mình rất thích con Sharp này (mặc dù chưa xài bao h nhưng chỉ nghe các
pác nói mình đã thấy phê lòi mắt rồi). Các bạn cho mình hỏi 1 câu (các
bạn đừng chê mình ngu nhé tội nghiệp mình) : cái máy này đem sang Anh
dùng mạng Vodafone là dùng vô tư ah`? Nếu dùng được bên Anh mà không
phải chọc ngoáy j thì mình mua một cái

Don’t care about its meaning, what I want to achieve is an array of hashes containing the results with 2 pairs: value => the value of extracted phrases, starting_position => the position of the first character.

According to the example about, it should be like this:
[{:value=>”con Sharp”, :starting_position => 16}, {:value=>”bao h”, :starting_position => blah blah}…]

This means that all words containing \W characters, such as “mình”, “rất”, “thích”, etc. are rejected.

Trying above example with this regex on rubular.com for Ruby 1.9.2:

\b[\w|\s]+\b

I nearly got my desired phrases (except space-only ones), but it seems not working on my Ruby, which is also 1.9.2p290, using Win 7 64-bit.

Any ideas would be highly appreciated. Thank you beforehand.

  • 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-01T07:08:21+00:00Added an answer on June 1, 2026 at 7:08 am

    According to rubular, it looks like \w matches all ascii letters and numbers (and underscored), but \b is working well for all Unicode letters. That is a little confusing.

    What you want, however, are all sequences of ASCII words. This should match them:

    /\b[a-z]+\b(?:\s+[a-z]+)*\b/i
    

    Working example: http://www.rubular.com/r/1iewl7MpJe

    A quick explanation:

    • \b[a-z]+\b – first ASCII word.
    • (?:\s+[a-z]+) – any number of spaces and words – at least one space and one letter each time.
    • \b – to assure the last word doesn’t end in the middle of another word, like n in "con Sharp này".

    I’m not sure about getting an hash, but you can get all MatchDatas, similar to:
    How do I get the match data for all occurrences of a Ruby regular expression in a string?

    s = "hello !@# world how a9e you"
    r = /\b[a-z]+\b(?:\s+[a-z]+)*\b/i
    
    matches = s.to_enum(:scan, r).map { Regexp.last_match }
               .map {|match| [match.to_s(), match.begin(0)]}
    puts matches 
    

    Here’s an example on ideone: http://ideone.com/YRZE5

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

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.