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;

public class Test1
{
    public static void main(String[] args)
    {
        if (args.length < 1) {
            System.err.println("Failed to specify a regex");
            return;
        }

        String sensitiveData; //represents sensitive data from a file or something
        //imagine a CSV style database: user,password
        sensitiveData import java.util.Set;
import java.util.HashSet;

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

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

        String regex = "$" + name + ","; //supposedly this forces the regex to only match names
        System.out.println("Pattern: \'" + regex + "\'");
        Pattern         Pattern p = Pattern.compile(regex, 0);
             Matcher  Matcher m = p.matcher(sensitiveDatauserCSV);

             while  while (m.find())
            System.out.println("Found \'" +             matchedUsers.add(m.group() + "\'");

        System.err.println("DONE");
          return matchedUsers;
    }
}

When searching using the regex '(?s)John.*', the program returns all the users' passwords. The (?s) turns on single-line matching support, which means new lines are ignored.

...