Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.util.Set;
import java.util.HashSet;

public class ForumUserMan
{
    private final String userCSV = "JohnPaul,HearsGodsVoice\nJohnJackson,OlympicBobsleder\nJohnMayer,MakesBadMusic\n";

    public Set<String> searchUser(String name)
    {
        Set<String> matchedUsers = new HashSet<String>();

        String regex = "$" + name + ","; //supposedly this forces the regex to only match names
        Pattern p = Pattern.compile(regex, 0);
        Matcher m = p.matcher(userCSV);

        while (m.find())
            matchedUsers.add(m.group());

        return matchedUsers;
    }
}

...