Changes

Jump to: navigation, search

OPS102 - Regular Expressions

2 bytes removed, 16:27, 6 December 2023
Examples
|An integer||<code><nowiki>^[-+]?[[:digit:]]+$</nowiki></code>||+15<br>-2<br>720<br>1440<br>1280<br>1920<br>000<br>012||+ 4<br>3.14<br>0x47<br>$1.13<br>$4||
|-
|A decimal number||<code><nowiki>^[-+]?[[:digit:]]+(\.[[:digit:]]*)?$</nowiki></code>||+3.14<br>42<br>-1000.0<br>+212<br>+36.7<br>42.00<br>3.333333333<br>0.976||.976<br>+-200<br>1.1.1.1<br>13.4.7||
|-
|A Canadian Postal Code||<code><nowiki>^[ABCEGHJKLMNPRSTVXY][0-9][ABCEGHJKLMNPRSTVWXYZ] ?[0-9][ABCEGHJKLMNPRSTVWXYZ][0-9]$</nowiki></code>||H0H 0H0<br>M3C 1L2<br>K1A 0A2<br>T2G 0P3<br>V8W 9W2<br>R3B 0N2<br>M2J2X5<br>M5S 2C6||POB 1L0<br>90210<br>MN4 2R6||A Canadian postal code alternate alternates between letters and digits: A9A 9A9. The first letter must be of of ABCEGHJKLMNPRSTVXY and the remaining letters must be one of ABCEGHJKLMNPRSTVXY.
|-
|Phone Numbers (Canada/US)||<code><nowiki>^[^+[:digit:]]*(\+?1)?[^+[:digit:]]*[2-9]([^+[:digit:]]*[0-9]){9}[^+[:digit:]]*$</nowiki></code>||(416) 967-1111<br>+1 416-736-3636<br>416-439-0000||+65 6896 2391<br>555-1212||A Canadian/US phone number consists of a 3-digit Area Code (which may not start with 0 or 1) and a 10-digit local number consisting of an exchange (3 digits) and a line (4 digits). The country code for Canada and the US is 1, so the number may be preceeded by +1 or 1. Area codes are sometimes contained in parenthesis, and dashes or spaces are sometimes used as separators.

Navigation menu