Click to See Complete Forum and Search --> : Regular expressions and string matching


DennyLoi
11-15-2007, 12:36 PM
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).

james_
11-15-2007, 04:57 PM
If you do this it probably won't work very well since there's likely to be some ambiguity for matching.

For instance, if you get the string ?anage? that could be both manager and manages.

Also I don't think that regular expressions are a great choice for this since you're mainly doing substring matching and not really using regular expressions.

DennyLoi
11-16-2007, 03:11 AM
The ambigouity should not appear for longer words. Eg - if i start with 12 letter words. And then from this, i can use the characters from these words to decrypt more of the letters.

Can you think of an alternative approach?