• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regex pattern doubt

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 113
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
\d+
This is numbers only ...
 
Tanu Gulati
Ranch Hand
Posts: 113
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic