Bookmark Topic Watch Topic
  • New Topic

regular expression

 
syed quadri
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
    Posts: 12196
    35
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Report post to moderator
    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.


     
    Jeff Verdegan
    Bartender
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Report post to moderator
    This seems to be a duplicate of http://www.coderanch.com/t/597776/java/java/find-out-digits-spaces-String.

    Locking.
     
      Bookmark Topic Watch Topic
    • New Topic