Skip to content

Instantly share code, notes, and snippets.

@afzafri
Created August 5, 2016 13:58
Show Gist options
  • Save afzafri/7cc1628d206b82192d1a5fe38afe87eb to your computer and use it in GitHub Desktop.
Save afzafri/7cc1628d206b82192d1a5fe38afe87eb to your computer and use it in GitHub Desktop.
import java.util.*;
import java.text.*;
public class regex {
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int i,j,n;
n = Integer.parseInt(input.next());
String words[] = new String[n];
for(i=0;i<n;i++)
{
words[i] = input.next();
}
System.out.println();
for(i=0;i<n;i++)
{
int alpabett = words[i].replaceAll("[^a-zA-Z]","").length();
int num = words[i].replaceAll("[^0-9]","").length();
int sp1 = words[i].replaceAll("[.*a-zA-Z0-9]","").length();
int sp2 = words[i].replaceAll("[^\\.\\*]","").length();
int specchar = sp1+sp2;
System.out.print("\nWord: "+words[i]+"\nAlphabets: "+alpabett+"\nNumbers: "+num+"\nSpecial Characters: "+specchar+"\n");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment