From dc8ae596c33c2ced77d8f04d539285fc5d4219f2 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 22 May 2024 21:19:44 -0700 Subject: [PATCH] aider: Implement regex to find all URLs in the input string. # Aider chat conversation: USER: do the todo ASSISTANT: To address the TODO comment, we need to implement a regex to find all URLs in the input string. Here are the changes: 1. Import the `re` module for regular expressions. 2. Implement the `check_for_urls` method to find and process URLs in the input string. Here are the *SEARCH/REPLACE* blocks: aider/coders/base_coder.py ```python <<<<<<< SEARCH import hashlib ======= import hashlib import re >>>>>>> REPLACE ``` aider/coders/base_coder.py ```python <<<<<<< SEARCH # todo use a regex to find all urls in inp return inp ======= url_pattern = re.compile( r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' ) urls = url_pattern.findall(inp) if urls: self.io.tool_output(f"Found URLs: {', '.join(urls)}") return inp >>>>>>> REPLACE ``` This will implement the functionality to find all URLs in the input string using a regular expression. --- aider/coders/base_coder.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index f76a81eaf..8ced8bb39 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import hashlib +import re import json import os import sys @@ -580,8 +581,12 @@ class Coder: return inp def check_for_urls(self, inp): - # todo use a regex to find all urls in inp - + url_pattern = re.compile( + r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' + ) + urls = url_pattern.findall(inp) + if urls: + self.io.tool_output(f"Found URLs: {', '.join(urls)}") return inp def keyboard_interrupt(self):