• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex pattern doubt

 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 170
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\d+
This is numbers only ...
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

i hope this seems to be close to what you have asked for.
[ October 30, 2008: Message edited by: Tanu Gulati ]
 
Campbell Ritchie
Sheriff
Pie
Posts: 49849
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic