RegEx Please paste your commands after each question You are to define a pattern
ID: 3703460 • Letter: R
Question
RegEx
Please paste your commands after each question
You are to define a pattern for each requirement
1. Build a pattern for the word “license”, even if it is misspelled by mixing up the “c” and the “s”
2. Define a pattern to find the number 21 followed by a single lower- or uppercase letter
3. Define a pattern to find two uppercase letters in a row, followed by a single digit, followed by one lowercase letter
4. Build a pattern to find a number from 3 to 7:
5. An uppercase “X”, followed by any two digits
6. Letter X not followed by “a” or “o”:
7. At least one non-alphabetic character
8. Letter “H” followed by any letter from “a” to “z”
9. A single upper- or lowercase followed by a single digit, followed by a lowercase letter
10. Build a pattern to a Canadian postal code. These codes have the format “letter number letter space number letter number”, where all the letters are uppercase, for example, M5P 3G4
11. Define a pattern to find Uppercase letter “H” followed by zero or more lowercase letters
12. Define a pattern to “error” followed by zero or more characters, followed by “code”
13. Build a pattern to find a colon, followed by zero or more occurrences of any other characters, followed by another colon
14. Build a pattern to find the letters “variable” followed by one or more numbers
15. Build a pattern to match either an uppercase “V” or lowercase “v” at the beginning of the above pattern
16. Word “color” (American spelling) or “colour” (British spelling)
17. Match exactly 3 digits
18. Match at least 3 digits
19. Match 5 or fewer digits
20. Match 3 to 5 digits
21. Match any of the following words: cat, dog, bird, hamster
22. Match any of the following complete words: cat, dog, bird, hamster
23. Consider the lines below:
But remember to use these 3 digits: 76 2
There could be an error in 32variable3x
You can concatenate as well
Remember that errorcode 541 means “Too many parentheses”
That’s your licence to kill harlly
I know you like Harmonica, even your dog
We’ll now set Variable417
Build a pattern to find either 2- or 3-digit numbers
24. Write a regular expression that matches against hyphenated Social Security numbers.
25. Write a regular expression that matches URIs. Look at the IETF document RFC 3986 for the URIs generic syntax. You cannot use the regex it defines. Please illustrate your regex with some examples
Explanation / Answer
1.Build a pattern for the word “license”, even if it is misspelled by mixing up the “c” and the “s”
Ans: pattern will be "li[cs]en[cs]e" . it will check for c or s if they were misspelled.
--------------------------------------------------------------------------------------------------------------------------------------------------
2. Define a pattern to find the number 21 followed by a single lower- or uppercase letter
ans: pattern will be: "21[a-zA-Z]"
the command will be grep "21[a-zA-Z]" a.txt
it will find a pattern in a.txt file start with 21 followed by a single lower- or uppercase letter
--------------------------------------------------------------------------------------------------------------------------------------------------------
3. Define a pattern to find two uppercase letters in a row, followed by a single digit, followed by one lowercase letter
ans: Pattern will be "[A-Z][A-Z][0-9][a-z]"
the command will be grep "[A-Z][A-Z][0-9][a-z]" a.txt
it will find a pattern in a.txt file start two uppercase letters in a row, followed by a single digit, followed by one lowercase letter
------------------------------------------------------------------------------------------------------------------------------------------------------
4. Build a pattern to find a number from 3 to 7:
ans: pattern will be "[3-7]"
command will be grep "[3-7]" a.txt
--------------------------------------------------------------------------------------------------------------------------------------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.