This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Regex pattern doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Regex pattern doubt" Watch "Regex pattern doubt" New topic
Author

Regex pattern doubt

rakesh sugirtharaj
Ranch Hand

Joined: Dec 16, 2007
Posts: 151
Hi,

I want to write a regex pattern that would replace pure numbers with "".
Example 3434 - must be replaced by "" but W3C - should be left untouched. Any ideas?


Cheers!
RSR
Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113

I want to write a regex pattern that would replace pure numbers with "".
Example 3434 - must be replaced by "" but W3C - should be left untouched. Any ideas?
-----------------------------------------------------------
for input "3443uierei783 32gh" you want the output as "uierei gh", correct??

if yes then you can use Scanner class and its API and break the current strings in to tokens and then append these tokens to a string.


thanks
Tanu Gulati
rakesh sugirtharaj
Ranch Hand

Joined: Dec 16, 2007
Posts: 151
No thats not what i want. May be i ll explain further. Say i have list of words - "rakesh","w3c","345" (in a arraylist). I want to remove the "345" from the list. For that i m trying to iterate over the list and if my regex matches for a pure number i intend to remove that entry in the list.

Please suggest a regex or may be a whole new way to do this.
vanlalhmangaiha khiangte
Ranch Hand

Joined: Sep 11, 2006
Posts: 170
\d+
This is numbers only ...
Tanu Gulati
Ranch Hand

Joined: Oct 06, 2008
Posts: 113


i hope this seems to be close to what you have asked for.
[ October 30, 2008: Message edited by: Tanu Gulati ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37907
    
  22
Whenever this sort of question comes up I tell people to read the Java Tutorials. Look through that section; there are tags with "b" in for word Boundary. Adding those tags to the \d+ might help.
Using Pattern and Matcher you can get a reference to the substring which matched. Can't remember how to do it, but it's all in the Tutorial.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regex pattern doubt
 
Similar Threads
Remove non-letter characters from String
Regex reluctant mode problem
Pattern with wildcards
finding hardcoded string
Need help with regexp