9

As per title, what is the difference between:

\d+ and \d- \w+ and \w-

in regular expression terms? What influence has + and - ?

1
  • - only has significance if used in a character class when identifying a range, as in [a-z], otherwise it carries its literal meaning. Dec 4, 2013 at 12:53

1 Answer 1

24

\d+ means one or more digit [0-9] (depending on LOCALE)
\d- means a digit followed by a dash -

\w+ means one or more word character [a-zA-Z0-9_] (depending on LOCALE)
\w- means a word char followed by a dash -

2
  • 1
    \w includes numerics [a-zA-Z0-9_]. The exact range can be adjusted by flags ASCII and LOCALE.
    – cdarke
    Dec 4, 2013 at 12:43
  • @M42 the same goes for \d, it might also match hindu-arabic digits
    – HamZa
    Dec 4, 2013 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.