1
0
mirror of https://github.com/akaessens/NoFbEventScraper synced 2025-06-05 23:29:13 +02:00

use regex find instead of replace for url matching

This commit is contained in:
akaessens
2020-08-26 18:47:44 +02:00
parent 57b00e2e57
commit 05f3ba9a33
2 changed files with 12 additions and 5 deletions

View File

@ -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();