Bug 4057 - \w does not match underscore
Summary: \w does not match underscore
Status: CLOSED DUPLICATE of bug 19329
Alias: None
Product: Regexp
Classification: Unclassified
Component: Other (show other bugs)
Version: unspecified
Hardware: All All
: P3 major with 3 votes (vote)
Target Milestone: ---
Assignee: Jakarta Notifications Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2001-10-09 16:46 UTC by Frank McGrath
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Frank McGrath 2001-10-09 16:46:36 UTC
The \w pattern should match the underscore ("_") character.  It does not - the 
implementation just calls java.lang.Character.isLetterOrDigit().  This method 
returns false for underscore.
Comment 1 Bob Dickinson 2001-11-15 00:37:24 UTC
I also observed this problem.  I noticed something else: if I wrap the \w in a 
character class by itself (i.e. [\w]) then it does match underscores.  I wrote 
a test app to verify the observed behavior.  The output is provided below:

"\w+" matched target: "a" - matching part was "a" 
"\w+" did not match target: "_"
"[\w]+" matched target: "_" - matching part was "_" 
"^\w+$" did not match target: "under_score" 
"^[\w]+$" matched target: "under_score" - matching part was "under_score" 
"^[\w]+$" did not match target: "under#_score" 

Comment 2 Vadim Gritsenko 2003-04-25 17:58:52 UTC

*** This bug has been marked as a duplicate of 19329 ***
Comment 3 Vadim Gritsenko 2003-05-02 01:09:50 UTC
Fixed by Bug #19329