-5

3 days im working on regular expressions and something got stuck in my head here is the thing; i want my regex to accept like this one

0 123 456 78 90

0355 369 5878

01234567890

last one is easy to do, like

"(0[0-9]);

but i dont know the rest on java

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Umut Mert
  • 3
  • 6
  • What are you working on? What is the issue? – Wiktor Stribiżew Oct 20 '15 at 13:02
  • Why do you need the leading `0`, the `;`, the parens, and the `"`? According to your question, you are simply trying to match numeric strings. You can just use `^[0-9 ]+$`. It matches any string composed of _only_ and _at least one_ number or whitespace character. You didn't specify capturing text `(...)` in your question. – Arc676 Oct 20 '15 at 13:09
  • thanks!! thats what i mean (sorry for not being clear its little hard for me to explain myself in english) – Umut Mert Oct 20 '15 at 13:14

1 Answers1

0

looks you are checking phone number,

this RE works well with given data.

private static void myregex(String txt) {
        Pattern myREphone = Pattern.compile("0[\\s]?\\d{3}[\\s]?\\d{3}[\\s]?\\d{2}[\\s]?\\d{2}");
        Matcher mymatchsphone = myREphone.matcher(txt); 
        if (mymatchsphone.find()) System.out.println(txt.substring( mymatchsphone.start(), mymatchsphone.end()));
    }
Belhe001
  • 89
  • 9