| Author |
Regex doubt
|
sravanthi pulukuri
Ranch Hand
Joined: Mar 15, 2007
Posts: 125
|
|
import java.util.regex.*; public class searchesUsingQuantifiers51{ public static void main(String args[]){ Pattern p = Pattern.compile("\\d\\d\\d([-\\s])?\\d\\d\\d\\d"); Matcher m = p.matcher("123%456 1234567 123 4567 1234-4567"); boolean b = false; while(b=m.find()){ System.out.println(" At Position " + m.start() + " the o/p is " + m.group()); } } }
|
 |
Srinivasan thoyyeti
Ranch Hand
Joined: Feb 15, 2007
Posts: 557
|
|
Hi Sravanthi, I will prefer to meaning of pattern rather than output Meaning of ("\\d\\d\\d([-\\s])?\\d\\d\\d\\d"), find me: 1.\\d\\d\\d : three consecutive digits, after that 2.([-\\s])? : ? means 0 or 1 occurance of - or \\s(space) , after that 3.\\d\\d\\d\\d: four consecutive digits. Important Point: Matcher never considers consumed input. Suppose Things are pretty clear now.
|
Thanks & Regards,<br />T.Srinivasan,<br />SCWCD 1.4(89%),SCJP 5.0(75%)<br />"That service is the noblest which is rendered for its own sake." - Mahatma Gandhi
|
 |
 |
|
|
subject: Regex doubt
|
|
|