Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

# MetaCharacter Problem(See if you can Solve it)

Harshit Sethi
Ranch Hand
Posts: 75

Run this program with statement:java Parsing "0[xX]([0-9 a-f A-F])+" "0x1FE 320x 0xfF 0xA"

My doubt is that i am not getting 0xA as a hexadecimal number in the output why is that?

Ranch Hand
Posts: 446
1
the command line arguments are all the Strings
did you get the hint?
[EDIT]
and yes
I forgot to tell
UseCodeTags
QuoteYourSources

happy learning
[/EDIT]

Harshit Sethi
Ranch Hand
Posts: 75
no.please Explain a little bit more

Ranch Hand
Posts: 446
1
and UseCodeTags
that will really make people easier for helping you

Harshit Sethi
Ranch Hand
Posts: 75
ok thanks i have done that now tell me what's the problem .The two Command Line Arguments are already in quotes

Ranch Hand
Posts: 446
1
hahaha
QuoteYourSources means mention the book or web site from where you got this question
let it be

first of all let me apologize that I mislead you about the question
the problem is not with command line arguments

it is with the String you are passing
the pattern should be

0[xX][0-9a-fA-F]

and not the

0[xX][0-9 a-f A-F]

the spaces should not be there
it causes the different output

Harshit Sethi
Ranch Hand
Posts: 75
I firstly didn't include any spaces between them but then because i didn't get the last hexadecimal number then i did that way but the result was same .

This problem is from Kathy Sierra but the second command line argument i have taken as random choice of mine.

Ranch Hand
Posts: 446
1
does that mean that problem is not solved?
because I had the output as expected

this is it

C:\Users\Prasad\Desktop>java Parsing "0[xX]([0-9 a-f A-F])+" "0x1FE 320x 0xfF 0x
A"
0 9 0x1FE 320
11 17 0xfF 0

C:\Users\Prasad\Desktop>java Parsing "0[xX]([0-9a-fA-F])+" "0x1FE 320x 0xfF 0xA"

0 5 0x1FE
11 15 0xfF
16 19 0xA

Harshit Sethi
Ranch Hand
Posts: 75
Yeah ,problem is solved ,thanks.But why does space makes such a difference in square brackets?

Deepak Bala
Bartender
Posts: 6663
5
The regex engine in java is sensitive to it. Take a look at this code

The output should help explain your problem

Harshit Sethi
Ranch Hand
Posts: 75
It means we can use either "\s" or manually insert space in square brackets.Thats the same thing .Isn't it?

Deepak Bala
Bartender
Posts: 6663
5
Regex \s is a short for [\t\n\x0b\r\f]