473,383 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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).
Nov 15 '07 #1
7 2223
JosAH
11,448 Expert 8TB
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).
Yes you can do that: the regular expression ".anage." matches "manager" but
you have to check all your words in your dictionary for a possible match which
can be quite slow. Google for "PATRICIA" trie and see how this can be done a
bit more clever. Your dictionary needs probably be changed structurally for that.

kind regards,

Jos
Nov 15 '07 #2
r035198x
13,262 8TB
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).
The * wildcard is your friend here. You can read more about it.
Nov 15 '07 #3
JosAH
11,448 Expert 8TB
The * wildcard is your friend here. You can read more about it.
Erm, make that a dot instead of a star. Regular expressions are not globbing.

kind regards,

Jos
Nov 15 '07 #4
r035198x
13,262 8TB
Erm, make that a dot instead of a star. Regular expressions are not globbing.

kind regards,

Jos
No they are not.
. it is.
From my very own link!



These leaves us with:
  • Replace any * characters with .*
  • Replace any ? characters with .
  • Leave square brackets as they are.
  • Replace any characters which are metacharacters with a backslashified version.
Nov 15 '07 #5
JosAH
11,448 Expert 8TB
No they are not.
. it is.
From my very own link!
Hrmph; your quote is gone in my reply; but that's not how Posix regular expressions
work: a dot is a single char that matches anything and a star is a reflexive closure
of the previous regular expression (i.e. the regex to the left of it). What you described
resembles a globbing pattern to a regular expression conversion.

kind regards,

Jos
Nov 15 '07 #6
r035198x
13,262 8TB
...What you described
resembles a globbing pattern to a regular expression conversion.

kind regards,

Jos
That's what was being explained at the point that I extracted.
Which is what I should have done(the conversion that is).
Nov 15 '07 #7
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?
Nov 16 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
11
by: Martin Robins | last post by:
I am trying to parse a string that is similar in form to an OLEDB connection string using regular expressions; in principle it is working, but certain character combinations in the string being...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
3
by: Zeba | last post by:
Hi guys, I need some help regarding regular expressions. Consider the following statement : System.Text.RegularExpressions.Match match =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.