how to compare one string with another dynamic length pattern string?
Hi, I want to compare one string (str1) with another string (str2) pattern. Actually str1 is the input string and str2 is the pattern of the string. This pattern contains only and only ‘R’ character. No of ‘R’ character is not predefined here. More precisely, str2 can be sometime RR, str2 can be sometime RRRRRRR. But str2 can never contain any character except ‘R’.
Now I can do it, by using a for(int i=0;i<str2.length(),i++)if(str1.charAt[i].equals(str2.charAt[i])) but this method is time consuming, as I am scanning each character in both strings. Please help. Can regular expression work here?