Regular expression to extract URL from an HTML link

If you’re only looking for one: import re match = re.search(r’href=[\'”]?([^\'” >]+)’, s) if match: print(match.group(1)) If you have a long string, and want every instance of the pattern in it: import re urls = re.findall(r’href=[\'”]?([^\'” >]+)’, s) print(‘, ‘.join(urls)) Where s is the string that you’re looking for matches in. Quick explanation of the … Read more

Using regular expressions to validate a numeric range

Using regular expressions to validate a numeric range To be clear: When a simple if statement will suffice if(num < -2055 || num > 2055) { throw new IllegalArgumentException(“num (” + num + “) must be between -2055 and 2055”); } using regular expressions for validating numeric ranges is not recommended. In addition, since regular … Read more