If you find better and short solution pls let me know.
-
Task 1
Check if a string contains the wordword
in it (case insensitive). If you have no idea, I guess you could try/word/
.Regular Expression
\bword\b
And enable the "i" flag
Your shortest solution thus far is 11 characters long. The overall shortest solution is 11 characters long.
-
Task 2
Use substitution to replace every occurrence of the wordi
with 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 theSubstitution
field when using substitution.Regular Expression
\bi\b
Substitution
I
Your shortest solution thus far is 9 characters long. The overall shortest solution is 9 characters long.
-
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 return3
with the textABcDeFO!
. Note: Only ASCII. We considerY
to be a consonant! Example: the regex/./g
will return 3 when run against the stringabc
.Regular Expression
[^AEIOUa-z_\W\d]
Your shortest solution thus far is 19 characters long. The overall shortest solution is 16 characters long.
-
Task 4
Count the number of integers in a given string. Integers are, for example:1, 2, 65, 2579
, etc.Regular Expression
\ d+
Your shortest solution thus far is 6 characters long. The overall shortest solution is 6 characters long.
-
Task 5
Find all occurrences of 4 or more whitespace characters in a row throughout the string. Regular Expression\s{4,}
Your shortest solution thus far is 9 characters long. The overall shortest solution is 9 characters long.
-
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\1
Substitution
$1
Your shortest solution thus far is 12 characters long. The overall shortest solution is 12 characters long.
-
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 validate172.16.254.1
.Regular Expression
^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(?:.(?!$)|$)){4}$
Your shortest solution thus far is 77 characters long. The overall shortest solution is 40 characters long.
-
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
Your shortest solution thus far is 23 characters long. The overall shortest solution is 14 characters long.