Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <regex>
- // Function to check if a URL should be blocked
- bool shouldBlockURL(const std::string& url) {
- // Define your rules for blocking URLs using regular expressions
- std::regex adRegex(".*ad\\.com.*");
- std::regex spamRegex(".*spam\\.com.*");
- // Check if the URL matches any of the blocking rules
- if (std::regex_match(url, adRegex) || std::regex_match(url, spamRegex)) {
- return true;
- }
- return false;
- }
- int main() {
- // Read the URLs from a file
- std::ifstream file("urls.txt");
- if (!file) {
- std::cerr << "Failed to open the file." << std::endl;
- return 1;
- }
- std::string url;
- while (std::getline(file, url)) {
- // Check if the URL should be blocked
- if (shouldBlockURL(url)) {
- std::cout << "Blocked URL: " << url << std::endl;
- // You can perform additional actions here, such as hiding the ad or logging the blocked URLs.
- } else {
- std::cout << "Allowed URL: " << url << std::endl;
- }
- }
- file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement