Results 1 to 2 of 2
- 11-15-2007, 06:46 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
regular expressions and string matching
Hi everyone,
Here is my problem, I have a partially decrypted piece string which would appear something like.
Partially deycrpted: the?anage??esideshe?e
Plain text: themanagerresideshere
So you can see that there are a few letter missing from the decryped text. What I am trying to do it insert spaces into the string so that I get:
The ?anage? ?esides he?e
I have a method which splits up the string in substrings of varying lengths and then compares the substring with a word from a dictionary (implemented as an arraylist) and then inserts a space.
The problem is that my function does not find the words in the dictionary because my string is only partially decryped.
Eg: ?anage? is not stored in the dictionary, but the word “manager” is.
So my question is, is there a way to build a regular expression which would match the partially decrypted text with a word from a dictionary (ie - ?anage? is recognised and “manager” from the dictionary).
- 11-16-2007, 10:15 AM #2
Member
- Join Date
- Nov 2007
- Posts
- 2
- Rep Power
- 0
I wrote the following method in order to test the matching using . in my regular expression.
public void getWords(int y)
{
int x = 0;
for(y=y; y < buff.length(); y++){
String strToCompare = buff.substring(x,y); //where buff holds the partially decrypted text
x++;
Pattern p = Pattern.compile(strToCompare);
for(int z = 0; z < dict.size(); z++){
String str = (String) dict.get(z); //where dict hold all the words in the dictionary
Matcher m = p.matcher(str);
if(m.matches()){
System.out.println(str);
System.out.println(strToCompare);
}}}
// System.out.println(buff);
}
If I run the method where my parameter = 12, I am given the following output.
aestheticism
aestheti.is.
demographics
de.o.ra.....
Which suggests that the method is working correctly.
However, after running for a short time, the method cuts and gives me the error:
PatternSyntaxException:
Null(in java.util.regex.Pattern).
Does anyone know why this would occur?
Similar Threads
-
Simple demo of CSV matching using Regular Expressions
By Java Tip in forum java.utilReplies: 0Last Post: 04-16-2008, 10:59 PM -
Using Quantifiers in regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 01-10-2008, 10:43 AM -
Handling regular expressions using Regex
By Java Tutorial in forum Java TutorialReplies: 0Last Post: 01-07-2008, 12:46 PM -
Capturing Groups using regular expressions
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:19 AM -
Regular expressions quantifiers
By Java Tip in forum Java TipReplies: 0Last Post: 12-25-2007, 11:18 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks