vendredi 22 avril 2016

Replacing with this pattern doesn't work as I would expect it to what's wrong? [duplicate]

This question already has an answer here:

I need help on extracting some words from this sentence:

String keywords = "I like to find something vicous in somewhere bla bla bla.\r\n" + 
            "http://ift.tt/1YKj5m8";

And my matching code looks somewhat like this:

    keywords = keywords.toLowerCase();
    regex = "(I like to find )(.*)( in )(.*)(\\.){1}(.*)";
    regex = regex.toLowerCase();
    keywords = keywords.replaceAll(regex, "$4 $2"); //"$4 $2");

And I want to extract the words between find and " in " and between " in " and the first dot. however, as the url has multiple dots, some weird stuff starts happening and I get what I need PLUS the url wit dots replaced with empty spaces. I want the url to be gone, because it's supposed to be the (.*) in my case, and I did specify that I only need one dot after my words with (\.){1}, so I wonder what's going wrong there? Any ideas?

Aucun commentaire:

Enregistrer un commentaire