View Full Version : Mini Seti application(regular expressions)

05-16-2008, 07:00 AM
Can I please have some help over here with a program,more the algorithm..I can't figure it out all the cases for this problem:

"Mini Seti"
The application has 2 components:
Reception(server) wich generates a random list of string characters(>1000) and sends them for the processing to the client(processing units).
Reciever(client) search in the list of characters a regular expression.
The answer for the client would look like this(total number of apparitions,the context of the apparition.

Example(in the ASCII code):
Server sends the following code(characters from 48 to 122 in ASCII):

The client for example searches for the expression ".[0-9]." which means anythingnumberanything. Answer should look like this:
(number of aparitions,d73 73j l39 392 92m x30 30v ]3p p2i i4j j59 59d......and so on)

My problem here is that I cannot view all of them because my find() function only gets the list once and doesnt show expressions like: d73 73j cause find function doesnt look back.

Here is the part of the code I need to get it work(the client):

import java.net.*;
import java.io.*;
import java.util.regex.*;

public class Client {

public static void main(String[] args) throws IOException
String adr_server="";
int PORT=8111;
Socket s1=null;
PrintWriter out=null;
BufferedReader in = null;
String feedback=new String();

s1 = new Socket(adr_server,PORT);
out=new PrintWriter(s1.getOutputStream(),true);
in=new BufferedReader(new InputStreamReader(s1.getInputStream()));

System.out.println("Am primit de la server " +feedback);
Pattern p = Pattern.compile( ".[0-9].");
Matcher m = p.matcher(feedback);
String rasp="";
int i=0;

//System.out.println("am gasit "+m.group());
rasp+=m.group()+" ";
System.out.println("Am gasit asemanari in numar de: " +i);

}catch(UnknownHostException e)
System.err.println("Serverul nu poate fi gasit "+e);

05-16-2008, 06:35 PM
drop characters from the beginning and repeat the matching iteratively till you find all matches and save only the unique ones...sorta like this

String s = "ajd73jcl392mx30v;]3p2i4j59d9i3o23j4v0su345imsdf-f4-i35876hl2f";
HashSet<String> matches = new HashSet<String>();

while ( s.length() > 3 /* match cannot succeed below this */ ) {
Matcher m = Pattern.compile(".[0-9].").matcher(s);
while ( m.find() ) {
s = s.substring(1);

// now matches contains all the possible matches

05-16-2008, 08:05 PM
hey..thanks for your reply...but the program is supposed to work with any regular expressions not only with the ones that have length of 3. Also encounters of the expression on the same index should only be printed out once..

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum