The question is How many email addresses are in �first.last� name format AND involve someone who�s first name starts with a letter in the first half of the alphabet?
Relevant commands, code, scripts, algorithms:
Using grep command only
The attempts at a solution (include all code and scripts):
Here's what I tried to search all email addresses, but I don't know to search first.last name and involve someone who�s first name starts with a letter in the first half of the alphabet?
As your task is to use grep only, you'll may use a feature of grep instead. Look at the manpage( man grep ) again. There should be an option which counts the results.
In general regular expressions can be quiet hard. One possible way to get through a task is to begin simple and after each successful attemp take the next step, like this....
Step 1: Just look at the @:
grep '@' list.txt
Step 2: Include the part after the @:
grep -E -o "@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}"
and so on.
----
Your expression looks quite good. If you assume two-part domains only(...@domain.com not ...@sub.domain.com) the regex is good.
You are already using character sets("[...]": a list of wanted characters) and quantifiers("+", or "*" or "{n,m}":how often are they supposed to be there). How would you express firstname with character sets and and quantifiers? The same for lastname? If you have it, just put it together like you did already at an other place within your regex.
Dumb question: What characters are exactly in the first half of the alphabet? How would you express that with the construct of a character set "[...]" for the very first character of the firstname? You already used a range(like this: "[A-Z]") in a character set, which will be handy here. Then describe the rest of firstname using another character set.
To create a RegEx pattern, this is a simple procedure, that helps
What char (fixed character, list of possible characters, special character classes) do I want now? -> define the character
How often should it be there? -> write the quantifier(if needed)
Do more characters form a group and this group should be repeated? -> put parenthesis around the group and use the correct quantifier