If you find better and short solution pls let me know.
-
Task 1 Check if a string contains the word
wordin it (case insensitive). If you have no idea, I guess you could try/word/.Regular Expression
/\bword\b/i
-
Task 2 Use substitution to replace every occurrence of the word
iwith the wordI(uppercase, I as in me). E.g.:i'm replacing it. am i not?->I'm replacing it. am I not?. A regex match is replaced with the text in theSubstitutionfield when using substitution.Regular Expression
/\bi\b/g
Substitution
I
-
Task 3 With regex you can count the number of matches. Can you make it return the number of uppercase consonants (B,C,D,F,..,X,Y,Z) in a given string? E.g.: it should return
3with the textABcDeFO!. Note: Only ASCII. We considerYto be a consonant! Example: the regex/./gwill return 3 when run against the stringabc.Regular Expression
/[B-DF-HJ-NP-TV-Z]/g
-
Task 4 Count the number of integers in a given string. Integers are, for example:
1, 2, 65, 2579, etc.Regular Expression
/\d+/g
-
Task 5 Find all occurrences of 4 or more whitespace characters in a row throughout the string. Regular Expression
/\s{4,}/g
-
Task 6 Oh no! It seems my friends spilled beer all over my keyboard last night and my keys are super sticky now. Some of the time whennn I press a key, I get two duplicates. Can you ppplease help me fix thhhis?
Regular Expression
/(.)\1{2}/g
Substitution
$1
-
Task 7 Validate an IPv4 address. The addresses are four numbered separated by three dots, and can only have a maximum value of 255 in either octet. Start by trying to validate
172.16.254.1.Regular Expression
/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)(?:.(?=\d)|$)){4}$/
-
Task 8 Strip all HTML tags from a string. HTML tags are enclosed in
<and>. The regex will be applied on a line-by-line basis, meaning partial tags will need to be handled by the regex. Don't worry about opening or closing tags; we just want to get rid of them all. Note: This task is meant to be a learning exercise, and not necessarily the best way to parse HTML.Regular Expression
]*>|<[^<>]*>?
Substitution
-
Verify that a given e-mail address is valid.
We all know how complex emails are, but despite this, let's give it a try and see what we can come up with.
You could start by trying to match
contact@regex101.com(denoted as<local-part>@<domain>.<top-level-domain>).Regex
^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,}$
error: Test 17/56:
.example.cois not a valid domain. -