Regex Syntax
Characters
| Description | Example | ||
| match | Doesn't match | ||
| . | Any character | X | [everything matches] |
| [abcde] | A character of the set {abcde}* | a | A or f or # |
| [^abcde] | A character which is not in the set {abcde}* | A or g | c |
| [a-z0-9] | A character in the sets {a,b,c...z} {0,1,2...9}* | b | B or # |
| \w | [a-zA-Z0-9_] (literal or digit or underscore) | B or 9 or _ | # or " "(space) |
| \W | [^a-zA-Z0-9_] (not literal nor digit nor underscore) | # or " " (space) | B or 9 _ |
| \d | [0-9] (digit) | 8 | A or # |
| \D | [^0-9] (not a digit) | A or # | 8 |
| \s | Space | " " | A or 8 or # |
| \S | No space | A or 8 or # | " " |
| \xdd | dd is a hexadecimal number. Matches the character with ascii code dd. | \x41 matches A \x40 matches @ | |
| \udddd | dddd is a hexadecimal character. Matches the character with unicode code dddd. | \u0013 matches # \u0030 matches @ | |
* Metacharacters Inside Character Classes:
Validar direccion email:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
Validar direccion email (permite email vacio):
^(\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)??\s*$
URL (protocolo, dominio, puerto, archivo, parametros):
\b(?i:https?|ftp)(://([\w.]+(:\d{1,4})?)(/[\w+&@#/%=~_!:,.;]*))?(\?[\w+&@#/%=~_|!:,.;]*)?
Valida IP: from 0.0.0.0 a 255.255.255.255 (no capture)
\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d{1,2})\b
Path (drive, folder, filename):
\b(?i:[a-z]):\\([^/:*?"<>]*\\)?([^\\/:*?"<>]*)
Valida caracteres sean numeros, letras y subrayado:
^[\w]*$
No hay comentarios:
Publicar un comentario