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" +
"https://address.suffix.com/level/somelongurlstuff";
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 matched with (.*)
in my case, and I only need one dot after my words with (\\.){1}
, so I wonder what's going wrong there? Any ideas?
By adding (?s)
or doing removing all new line characters on the line before matching on the regex gives you something like: somewhere bla bla bla address suffix something vicious
so the problem with the url without having dots still being left there persists.
This is NOT just about matching multiline text.