Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Python Regular Expressions Example
SUBMITTED BY:
Bun
DATE:
Feb. 20, 2016, 2:36 p.m.
FORMAT:
Python 3
SIZE:
207 Bytes
Raw
Download
Tweet
HITS:
1049
Go to comments
Report
import
re
for
test_string
in
[
'555-1212'
,
'ILL-EGAL'
]:
if
re
.
match
(
r
'^\d
{3}
-\d
{4}
$'
,
test_string
):
print
test_string
,
'is a valid phone number'
else
:
print
test_string
,
'invalid'
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus