Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-15-2007, 07:46 PM
Member
 
Join Date: Nov 2007
Posts: 2
DennyLoi is on a distinguished road
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).
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-16-2007, 11:15 AM
Member
 
Join Date: Nov 2007
Posts: 2
DennyLoi is on a distinguished road
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?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple demo of CSV matching using Regular Expressions Java Tip java.util 0 04-16-2008 11:59 PM
Using Quantifiers in regular expressions Java Tip Java Tips 0 01-10-2008 11:43 AM
Handling regular expressions using Regex Java Tutorial Java Tutorials 0 01-07-2008 01:46 PM
Capturing Groups using regular expressions Java Tip Java Tips 0 12-25-2007 12:19 PM
Regular expressions quantifiers Java Tip Java Tips 0 12-25-2007 12:18 PM


All times are GMT +3. The time now is 08:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org