This week's book giveaway is in the Testing forum.
We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line!
See this thread for details.
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

regex class

 
Ranch Hand
Posts: 41
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pattern p = Pattern.compile("\\d\\d\\d([-\\s])?\\d\\d\\d\\d");

want to search for a seven digit number (phone number)
1234567
123 4567
123-4567
are all correct findings...
this finder fails at the 123 4567 one
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah you sure that's exactly what you're testing? I ask because I just tried it out using http://www.regexplanet.com/advanced/java/index.html, and all three matched.
 
Sahil Manchanda
Ranch Hand
Posts: 41
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:Ah you sure that's exactly what you're testing? I ask because I just tried it out using http://www.regexplanet.com/advanced/java/index.html, and all three matched.


ya they work on your given link but on my command line one of them doesnt .... Strange!
thankyou for the help..
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you entering things via the command line then? What? And how are you doing it? Try printing out the regular expression and the test strings, to make sure they're actually what you think they are.
 
Ranch Hand
Posts: 82
Eclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ya they work on your given link but on my command line one of them doesnt .... Strange!



IF you are passing from command line, you have to use double quotes like "123 4567" to include spaces ,,,,
 
Sahil Manchanda
Ranch Hand
Posts: 41
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Don Redd wrote:

ya they work on your given link but on my command line one of them doesnt .... Strange!



IF you are passing from command line, you have to use double quotes like "123 4567" to include spaces ,,,,



IT WORKED NOW!
thanks man thankyou so much!
 
Ranch Hand
Posts: 924
1
Netbeans IDE Fedora Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
commanline treats space character as a seperator. if you need to pass commandline arguments containing spaces or other special characters as don said, you need to enclose it in double quotes to escape them so that the space character is treated as LITERAL SPACE in commandline lingo
 
I don't even know how to spell CIA. But this tiny ad does:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic