I have a pattern that needs to be matched in a string and I'm unable to figure out the correct regex pattern.
A string may contain multiple matches of this pattern and I need the count of it.
Starts with lowercase english letter.
Zero or more occurances of any of these - lower english letters, digits and colons.
one Forward slash - /
Sequence of one or more lower case english letters and igits.
one Backslash - \
Sequence of one or more lower case english letters.
So far I've succeeded in writing this pattern as follows:
Scanner sc=new Scanner(System.in);
String line=sc.nextLine();
String patern="(([a-z]+)([a-z0-9:]*)(\\/)([a-z0-9]+)(\\)([a-z]+))";
Pattern r=Pattern.compile(patern);
Matcher m=r.matcher(line);
int count=0;
while(m.find()) {
count+=1;
}
System.out.println(count);
But that's not giving me what I want. Any help from someone??