Results 1 to 2 of 2
  1. #1
    DennyLoi is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default 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).

  2. #2
    DennyLoi is offline Member
    Join Date
    Nov 2007
    Posts
    2
    Rep Power
    0

    Default

    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

  1. Replies: 0
    Last Post: 04-16-2008, 11:59 PM
  2. Using Quantifiers in regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-10-2008, 11:43 AM
  3. Handling regular expressions using Regex
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 01-07-2008, 01:46 PM
  4. Capturing Groups using regular expressions
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 12:19 PM
  5. Regular expressions quantifiers
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-25-2007, 12:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •