confused by this simple regular expressions behaviour

A

Adam Akhtar

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).
 
S

Stefano Crocco

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. To achieve what you want you need this:

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

Stefano
 
M

Mateusz Tybura

Adam said:
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
 
A

Adam Akhtar

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]???
 
S

Stefano Crocco

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]???

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

Stefano
 
P

Peña, Botp

RnJvbTogQWRhbSBBa2h0YXIgW21haWx0bzphZGFtdGVtcG9yYXJ5QGdtYWlsLmNvbV0gDQojIGlz
bnQgdGhlcmUgYSBzaG9ydGhhbmQgdmVyc2lvbiBmb3IganVzdCBsZXR0ZXJzIG9yIGRvIHlvdSAN
CiMgaGF2ZSB0byBhbHdheXMgd3JpdGUgb3V0ICBbYS16QS1aXT8/Pw0KDQp0cnkNCg0KICAgL1th
LXpdL2kNCg0Kb3INCg0KICAvW1s6YWxwaGE6XV0vDQoNCg0KDQpraW5kIHJlZ2FyZHMgLWJvdHAN
Cg==
 
D

David A. Black

Hi --

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top