Regex
Still under construction
Regular Expressions Cheat sheet
An “atom” can be a single character (“f”) or a grouping expression ( “(Mico)( )(Maco)”)
'.' - Any character (normally except new line)
'*' - none or many (of the previous "atom")
'+' - one or many (of the previous "atom")
'?' - none or one (of the previous "atom")
[aeo] - Character class: One of the included ([a-z]a matches "**ha**s", "**la**zy", "**wa**y", etc)
[^aeo] - Character class: Not the included ([^a-z]a matches "**Ma**ry had **a** little lamb.)
(includes everything **not** included in the character class)
\b - Word boundary /\PATTERN\b/
\\< \\> - Exact word boundaries (need to further investigate diference with \b)
() - will create a group that can be "called" by $n (being 'n' from left to rigt, the postion of each open brackets)
GNU GREP options (most useful to Mico Maco…)
-i - Case insensitive.
-E - Allows extended expressions. Linux GNU grep (the default grep) is already extended. "-E" only avoids backslashing ?, +, {, |, (, and ).
-o - Print only matching parts of a line (1 output line per match).
-H - Print (prefixed) the filename (-h cancels file printing. Useful when searching several files).
-n - Print (prefixed) the line number in the input file.
-w - Word boundaries (but will miss \_word\_ !!!)
-P - Use Perl regular expressions (allows lookahead and lookbehind patterns). See [here](https://www.regular-expressions.info/lookaround.html)
Find palindromes
^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?).?\9\8\7\6\5\4\3\2\1$ --> max 19 chars
IPv4
^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$ --> This admits 999.999.999.999
\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b
^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
Pending
URLS
$url1 = “http://www.somewebsite.com"; $url2 = “https://www.somewebsite.com"; $url3 = “https://somewebsite.com"; $url4 = “www.somewebsite.com”; $url5 = “somewebsite.com”;
URLs with url parameters
- grups
- anar endavant i enrere
Regular Expressions links
https://callumacrae.github.io/regex-tuesday/
https://alf.nu/RegexGolf
https://regex101.com
https://www.regextester.com/
https://www.regextester.com/22 –> IP4 Addresses (falla amb ports –> 1.2.3.4:80)
https://www.regextester.com/1965 –> URLs (pero admet coses rares com ’s.p’ o ‘[sapo.pt]cenas’)
https://www.regextester.com/19 –> Email
https://www.regextester.com/1911 –> PCRE email validator (algo rar. Es pcre)
https://www.regextester.com/1969 –> Match brackets (fails when anidated…)
https://www.regextester.com/1961 –> URLs a (entre “) per a un domnni donat…
https://regexone.com/references/python
https://regex.sketchengine.co.uk/
https://regexcrossword.com/
http://www.rexegg.com/regex-humor.html
http://www.regexlib.com/Default.aspx
http://www.regular-expressions.info/ip.html