Confused by this simple regular expressions behaviour

why does this regexpression match

\w+\d+

match 68 in this

"1/8 Fender '68 TELECASTER Miniature(Pink Paisley)[RARE]",

ive told it to at least match one letter before it matches any
numbers???

(i dont actually want it to match anything with this sentance).

···

--
Posted via http://www.ruby-forum.com/.

It's because \w stands for [a-zA-Z0-9], that is an uppercase letter or a
lowercase letter or a digit. To achieve what you want you need this:

/[a-zA-Z]+\d+/

Stefano

···

On Thursday 21 August 2008, Adam Akhtar wrote:

why does this regexpression match

\w+\d+

match 68 in this

"1/8 Fender '68 TELECASTER Miniature(Pink Paisley)[RARE]",

ive told it to at least match one letter before it matches any
numbers???

(i dont actually want it to match anything with this sentance).

Adam Akhtar wrote:

why does this regexpression match

\w+\d+

match 68 in this

"1/8 Fender '68 TELECASTER Miniature(Pink Paisley)[RARE]",

ive told it to at least match one letter before it matches any
numbers???

(i dont actually want it to match anything with this sentance).

It matchs on rubular (rubular.com) see:
http://www.rubular.com/regexes/946

···

--
Posted via http://www.ruby-forum.com/\.

hey stefano thanks for pointing that out...cant believe i missed that
one.

isnt there a shorthand version for just letters or do you have to always
write out [a-zA-Z]???

···

--
Posted via http://www.ruby-forum.com/.

Thanks Mateusz as well!

···

--
Posted via http://www.ruby-forum.com/.

Hi --

···

On Thu, 21 Aug 2008, Stefano Crocco wrote:

On Thursday 21 August 2008, Adam Akhtar wrote:

why does this regexpression match

\w+\d+

match 68 in this

"1/8 Fender '68 TELECASTER Miniature(Pink Paisley)[RARE]",

ive told it to at least match one letter before it matches any
numbers???

(i dont actually want it to match anything with this sentance).

It's because \w stands for [a-zA-Z0-9], that is an uppercase letter or a
lowercase letter or a digit.

And also underscore.

David

--
Rails training from David A. Black and Ruby Power and Light:
   Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL
   Advancing with Rails January 19-22 Fort Lauderdale, FL
See http://www.rubypal.com for details and updates!

As far as I know, there's not such shortcut.

Stefano

···

On Thursday 21 August 2008, Adam Akhtar wrote:

hey stefano thanks for pointing that out...cant believe i missed that
one.

isnt there a shorthand version for just letters or do you have to always
write out [a-zA-Z]???

# isnt there a shorthand version for just letters or do you
# have to always write out [a-zA-Z]???

try

   /[a-z]/i

or

  /[[:alpha:]]/

kind regards -botp

···

From: Adam Akhtar [mailto:adamtemporary@gmail.com]