Skip to content

Commit a78ffa1

Browse files
committed
checkin url_remove.py
1 parent 66e1074 commit a78ffa1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#! /usr/bin/env python
2+
3+
"""Module to remove URLs from a string."""
4+
5+
import re
6+
7+
8+
def remove_urls(text):
9+
"""
10+
Removes URLs from a string using a regular expression.
11+
12+
Args:
13+
text: The input string.
14+
15+
Returns:
16+
The string with URLs removed.
17+
"""
18+
url_pattern = re.compile(
19+
r"(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&\'\(\)\*\+,;=.]+",
20+
re.IGNORECASE,
21+
)
22+
return url_pattern.sub("", text)

0 commit comments

Comments
 (0)