wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

regular expression

syed quadri
Greenhorn

Joined: Nov 11, 2012
Posts: 10
Hello,

I am facing problem to find out digits using regular expressions. Could anyone please help ?

Is it possible ?

// Code

public static void main(String[] args)throws IOException {
int counter=0;


File f = new File("E:\\abc.txt");
f.createNewFile();
FileWriter br = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(br);
bw.write("Arsaedf123");
bw.newLine();
bw.write("abcd");
Pattern p = Pattern.compile("\\d");
Matcher m =p.matcher();
bw.close();

}
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Hi, and welcome to the Ranch!

It's not clear what you mean by "find out digits". Please TellTheDetails(←click) of what you're trying to accomplish. Some possible interpretations of "find out digits" are:

  • Determine if the string contains any digits at all.
  • Determine if the string consists of only digits.
  • Extract all digits or groups of digits from the string, for use on their own.


  • And there are others.

    In the mean time, note that the regex token to match a single digit is \d, which you would write as in a Java string literal.

    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 11161
        
      16

    I have copied your code into this post and used the code tags. It makes reading your java much easier, and we ask that everyone do this in their own post. If you don't know how to do it, please read this.




    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Jeff Verdegan
    Bartender

    Joined: Jan 03, 2004
    Posts: 6109
        
        6

    This seems to be a duplicate of http://www.coderanch.com/t/597776/java/java/find-out-digits-spaces-String.

    Locking.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: regular expression
     
    Similar Threads
    Doubt on Regular Expression
    How can I add error handling facilities to this code?
    Telephone format validation rule in java
    Just Java 2 book
    What's your fav jeans?