• 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

Have Simple Code Snippet, Please Point Out My Error

 
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

As seen below, I am trying to figure out how split my sample string so that the "012" is not placed into the string array. After reading the Javadocs, I know that ^0-9 and \D are equivalent, and my output confirms this, but I thought those would return anything NOT a digit. So I tried the regex [a-z][A-Z] on splitChar which I thought would return only letters, but as you see below, that succeeded in returning the whole sample string, digits and all.

This leads me to believe either I have a fundamental misunderstanding of how this whole regex thing works, or I am missing something easy in my code.




And here are my results from the above code:


Length is: 5
012
This
is
the
string

Length is: 1
012

Length is: 1
012

Length is: 1
012 This is the string




Thank you for your help. :-)

BD
 
Bd Howard
Greenhorn
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to get the result I was looking for using:

String[] splitNum = name.split("[0-9]{3}\\s");

I was hoping for a way to just take a shortcut in stripping out those digits, but it now appears to me that it will be a multi-step process to do what I want to do. The above code was just to learn what was going on.

Oh well. :-)

BD
 
reply
    Bookmark Topic Watch Topic
  • New Topic