<a href=" replacer

Published on Tue Mar 01 2022

to put # instead of url

Additional matching regexes for
<a href=" replacer

<a href=" replacer

to put # instead of url

Find php short open tags

Finds instances of <? instead of <?php

regex to get N words from a line

usefull if you want to return (N) words instead of (N) chars

Wikipedia anchor

Match Wikipedia anchor dot-instead-of-percent encoding string.replace(/((?:\.[a-f0-9]{2}){2})/ig, function(match) { return decodeURIComponent(match.replace(/\./g, '%')) });

Email address validator

Validates most email addresses. Using the range [A-Za-z0-9] at the beginning instead of \w means an address cannot begin with an underscore. This range is also used to exclude underscores from the domain (part after @).

JSON validator

Takes a JSON string and captures interesting information in the named capturing groups: (o: last object, a: last array, s: last string, n: last number, c: last comma before optional whitespace, d: same as c, but with a colon instead of a comma, v: last value)

Validate URLs

Someone on IRC posted the following site: https://mathiasbynens.be/demo/url-regex which challgenged me to write a decent regex to match valid URLs in that list. This regex works in both pcre and javascript (you'll have to replace the pcre-specific syntax to make it work in JS). Don't actually use this though, validate your URLs in a sane manner instead.

Lookahead phone test with formatting

Let's say a phone number is valid in case it has 11 digits only (13 in case of using 00 instead of +). Separators could be anywhere. Take the valid numbers and bring to common format. Original idea was deleting all non-digits but using look-ahead made impossible to use [^\d]+ for remove non-digits, it needs to capture each digits separately. Looking forward to prettier solution.