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:
@ -74,7 +74,7 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||||||
protected String fixLinks(String description_in) {
|
protected String fixLinks(String description_in) {
|
||||||
try {
|
try {
|
||||||
// @[152580919265:274:MagentaMusik 360] -> m.facebook.com/152580919265
|
// @[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]");
|
"$2 [m.facebook.com/$1]");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -25,6 +25,8 @@ import com.squareup.picasso.Picasso;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
@ -228,15 +230,20 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
// check for a valid uri
|
// check for a valid uri
|
||||||
new URL(str).toURI();
|
new URL(str).toURI();
|
||||||
|
|
||||||
if (str.matches(".*(facebook.com/events/[0-9]*).*")) {
|
Pattern pattern = Pattern.compile("(facebook.com/events/[0-9]*)");
|
||||||
return str.replaceAll(".*(facebook.com/events/[0-9]*).*",
|
Matcher matcher = pattern.matcher(str);
|
||||||
"https://m.$1");
|
|
||||||
|
if (matcher.find())
|
||||||
|
{
|
||||||
|
return "https://m." + matcher.group(1);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
error("Error: Invalid URL");
|
error("Error: Invalid URL");
|
||||||
clear(false);
|
clear(false);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Reference in New Issue
Block a user