Skip to content

Instantly share code, notes, and snippets.

@toddandrae
toddandrae / regex.md
Last active July 14, 2022 14:10
Find a potential URL in a string
(?<=\s|^|\")(?:[a-z]{3,255}:(?:\/\/)?)?(?:[a-z0-9]+(?:[\-\.]{1}[a-z0-9]+)*\.[a-z]{2,255})(?::[0-9]{1,5})?(?:[\/\?].*)?(?:(?<!\s|\")|(?:$))
@toddandrae
toddandrae / gist:cd563759bd35dad1f7bcebd3e1fc0fc4
Created July 12, 2022 20:52
grep to get user agent from access log, sort/filter/count output
grep -i '"[^"]*"$' /var/log/nginx/access.log --only-matching | sort | uniq -c | sort -nr
((literal, substitutions) => {
return ((literal, ...substitutions) => {
return new Function(substitutions, 'return `' + literal + '`;');
})(literal, Object.keys(substitutions))(...Object.values(substitutions));
})(
'template literal from string with ${replacement}. Is this a good idea? ${answer}',
{
'answer': '¯\\_(ツ)_/¯',
'replacement': 'substitution',
}