Introducing Regexps

Problem #150

Tags: regexp strings c-1 c-0 special

Who solved this?

No translations... yet

This is the first task to be solved with the help of regexps.

Your submission (in the Code field below) should consist of one or more lines, each consisting of two parts separated with space:

There should be no other code in any language, except these pairs of patterns!

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.

Problem statement

You are given a set of integers in decimal, octal, hex and binary format as they are used in several programming languages (derivatives from C and Assemblies):

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 and hex for hexadecimals. Strings which could not be recognized should be left unchanged.
Solution - i.e. your regexp - is also checked for this task.

Example:

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.

Note that your solution would be checked against another random-generated input data - not the set presented to you!

So valid regexp should be submitted in "solution" field, otherwise it won't pass!
You need to login to get test data and submit solution.