Introducing Regexps

Back to General discussions forum

mooninvader     2017-12-23 15:23:15

i never user regular expression in my life, so this seems to be a good starting point: i began with this simple line : [\w]* bin that normally will parse any number as a bin but i obtain binbin for each number past serious tries gave me something like octdec why this curious output and how should the answer look like please? thanks in advance

Quandray     2017-12-23 17:12:24
User avatar

The link to PHP Regexps on the problem page may help. There are many ways of doing it.
I had 8 lines and my line for detecting octal was
^0[0-7]+$ oct
where
^ means start
0 means first character must be 0
[0-7] means followed by 0-7
[0-7]+ means followed by 0-7 multiple times
$ means end

You need code that will identify each valid number format.

mooninvader     2017-12-23 17:53:45

thanks a lot it worked now i omited ^and especially the $ from the expressions

thanks again

adam.szaloki     2018-05-10 12:58:28

Can anyone tell me that what is wrong with my regexps? I always get the response: "Sorry, your regexps look incorrect: Error in line #3"

First 6 lines of my program:

    Regex regOctal = new Regex("^0[0-7]+$", RegexOptions.IgnoreCase);
    Regex regHex1 = new Regex("^0x[0-9ABCDEF]+$", RegexOptions.IgnoreCase);
    Regex regHex2 = new Regex("^[1-9][0-9ABCDEF]*H$", RegexOptions.IgnoreCase);
    Regex regBin1 = new Regex("^0b[01]+$", RegexOptions.IgnoreCase);
    Regex regBin2 = new Regex("^[01]+b$", RegexOptions.IgnoreCase);
    Regex regDec = new Regex("^[1-9][0-9]*$", RegexOptions.IgnoreCase);

Thanks in advance

Quandray     2018-05-10 13:18:02
User avatar

It says "Solution may start like:"
^0\d+ oct
but yours doesn't look like that.

OneMoreTime     2018-09-08 17:55:15

What is wrong with my solution? ^[^0\d+]^[^\D]$|^[1-9]+$ dec [0-9A-F]+H hex 0x[0-9A-F] hex x[0-9a-fA-F]+ hex 0b[01]+ bin [01]+b$ bin ^0[bB][01]+$ bin ^[01]+[Bb]$ bin 0b+[0-9]+ bin ^0[0-7] oct 0o[0-7]+ oct

Please login and solve 5 problems to be able to post at forum