shelllings

a practical way to learn shell
git clone https://git.davidvoz.net/shelllings.git
index
logs
tree
license

27_regex2.sh
1#!/bin/sh
2
3# Continuing off of regex
4#
5# [] matches with any one character from inside the brackets
6# [^] matches with any that are not in the brackets
7#
8# () groups parts of a pattern
9#
10# {} repeats what was shown before a certain amount of times
11# [a-zA-Z]{2,} All alphabet characters (lower and uppercase)
12# should be used 2 or more times
13# [a-zA-Z0-9]{5,15} All characters in square brackets should be used
14# a min of 5 times and max of 15
15#
16# `` same as $(...), but $() is preferred
17# \ backslash for the literal character
18#
19
20# We will verify valid email addresses below. We will keep it simple to
21# addresses with one word beginnings with numbers and letters, @,
22# and a website domain.
23# billybob@bob1.com, David2@test.xyz, etc
24
25verify() {
26 # don't forget the + symbol in some of these regex
27
28 # verify that the beginning has valid characters
29 echo "$1" | grep -Eq || exit 1
30
31 # verify that an @ symbol and a second level domain is present with
32 # only letters and numbers
33 echo "$1" | grep -Eq || exit 1
34
35 # verify a dot is present
36 echo "$1" | grep -Eq || exit 1
37
38 # verify the ending is a top level domain with 2 or more lowercase
39 # characters
40 echo "$1" | grep -Eq || exit 1
41}
42
43verify $1
44exit 0