This is the first task to be solved with the help of regexps.
Your Code should contain one or more lines, each consisting of two parts separated with space:
These regular expressions and substitutions are applied to each line of the input in order. If the given regexp will found the matching framgent inside the line, it will be substituted with the given pattern.
For example an input like this:
aaaaa bbbb aaabb
Could be processed with the following solution:
a+ X b+ Y
and the following result would be produced:
X Y XY
If input consists of several lines, they will be processed independently (though results are glued together into a single line with spaces).
Regexp format used here is one of PHP Regexps - it is very close to Perl-style regexps, I hope.
You are given a set of integers in
binary format as they are used in several
programming languages (derivatives from
0-7and starting with
0-9ABCDEFand starting with
hbut then it should not start with letter;
1000101b(though the single letter
bis not a number);
0-9are considered decimals (but not ones starting with zero - they should be regarded as octals and coul only contain digits
And your goal is to recognize these formats. Note that all letters (in hexadecimal values and in prefixes / suffixes) should be treated case-insensitively!
Input data will contain several "integers", each on separate line.
Answer should contain replacements for them -
dec for decimals,
oct for octals,
bin for binaries
hex for hexadecimals. Strings which could not be recognized should be left unchanged.
input data: 1347 0x80 013 101b answer: dec hex oct bin
Solution may start like:
^0\d+ oct \d+ dec ...
Use the button "RegExp" below to try your solution against sample input.