use regex find instead of replace for url matching
This commit is contained in:
parent
57b00e2e57
commit
05f3ba9a33
|
@ -74,7 +74,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||
protected String fixLinks(String description_in) {
|
||||
try {
|
||||
// @[152580919265:274:MagentaMusik 360] -> m.facebook.com/152580919265
|
||||
return description_in.replaceAll("@\\[([0-9]{10,}):[0-9]{3}:([^\\]]*)\\]",
|
||||
return description_in.replaceAll("@\\[([0-9]{10,}):[0-9]{3}:([^]]*)]",
|
||||
"$2 [m.facebook.com/$1]");
|
||||
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -25,6 +25,8 @@ import com.squareup.picasso.Picasso;
|
|||
import java.net.URL;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
@ -228,15 +230,20 @@ public class MainActivity extends AppCompatActivity {
|
|||
// check for a valid uri
|
||||
new URL(str).toURI();
|
||||
|
||||
if (str.matches(".*(facebook.com/events/[0-9]*).*")) {
|
||||
return str.replaceAll(".*(facebook.com/events/[0-9]*).*",
|
||||
"https://m.$1");
|
||||
Pattern pattern = Pattern.compile("(facebook.com/events/[0-9]*)");
|
||||
Matcher matcher = pattern.matcher(str);
|
||||
|
||||
if (matcher.find())
|
||||
{
|
||||
return "https://m." + matcher.group(1);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
error("Error: Invalid URL");
|
||||
clear(false);
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
Loading…
Reference in New Issue