Hi,

So I'm doing a project at the moment basically using classes, and extending them, creating objects etc.

It's an address book type deal, where you can create new contacts, and enter information about them, search through them for paticualr entries, and manage existing entries etc.

What I was wondering was, in the area of either searching through the contacts or even managing existing info, about the implementation of regular expressions into the program. I don't have any exp being taught it or anything, just from what I've read myself, but how hard is it to implement something like the following?

>Patterns for all the fields etc (Name, phone no., email etc.)
>Search Contacts Menu
>Input string
>Compare to patterns
>depending on which it matches (Or a manual confirmation between 2. Personal Name, and Company Name for eg.) goes into that paticular method in the 'Contact' class, (displayNameContaining, displayPhoneNoContaining etc which lists the matching contacts)

and that's pretty much it I think. In my head at least it seems a lot better type of program rather than having millions of menus to navagate, paticularly in the console window.

TL;DR
Is it hard to implement regex?

My biggest problem with looking up new programming stuff like this, is that I have no clue how to implement it into a program, (what I should import etc to get them working) so very literal advice is always welcome!


Thanks a mil and cheers for any input o/

//Resi

---------- Post added 2012-05-03 at 12:35 AM ----------

Okay so I have sorted the importing of the class etc, and I think I have it setup in a way where the only thing left to do is to input the syntax for each pattern.

any chance someone could have a quick look over my method for implementing this regex? :3 Thanks!

Code:
public int advancedCategorySearch(String input)
    {
        int answer = -1;
        
        //Name   / Company Name       Word Word  = 1                         
        //Initial -> Confirm which    One Letter = 2
        //Phone number  / Company     Ten Numbers = 3        
        //E-Mail / Company            x@word.word = 4
        //Age   -> Old/Younger?       One Number/Two Numbers/Three Numbers. = 5
        //Year                        Four Numbers = 6
        //Address      /Company       Leftover = -1  - default.
        
        Pattern namePattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher nameMatcher = namePattern.matcher(input);
        boolean nameAns = nameMatcher.matches();
        
              
        Pattern initialPattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher initialMatcher = initialPattern.matcher(input);
        boolean initialAns = initialMatcher.matches();
        
  
        Pattern phoneNoPattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher phoneNoMatcher = phoneNoPattern.matcher(input);
        boolean phoneNoAns = phoneNoMatcher.matches();
        
      
        Pattern eMailPattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher eMailMatcher = eMailPattern.matcher(input);
        boolean eMailAns = eMailMatcher.matches();
        
             
        Pattern agePattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher ageMatcher = agePattern.matcher(input);
        boolean ageAns = ageMatcher.matches();
        
    
        Pattern yearPattern = Pattern.compile("a*b");         //Synthaxs for each.
        Matcher yearMatcher = yearPattern.matcher(input);
        boolean yearAns = yearMatcher.matches();
        
        
        if(nameAns)
            answer = 1;    
        else if(initialAns)
            answer = 2;  
        else if(phoneNoAns)
            answer = 3;   
        else if(eMailAns)
            answer = 4;    
        else if(ageAns)
            answer = 5;             
        else if(eMailAns)
            answer = 6;
        
        
        
        
        return answer;
    }
The int it returns is an index to which methods it should actually go ahead and compare to the user inputed string.

The more I think about this, I'm starting the realise that a brute force 'CHECK EVERYTHING WITH THIS' would probably give the exact same output as this method ^^ but oh well!