-3

I have to create a java program to produce a regex between two numbers. I have already created a program for doing it for 10 base like this: [0-9], but I am not able to do it for another base like 16. Have you some ideas?

The input of the program are two numbers and the output is an regex to get all the number between the input numbers of the program. I'm able to do this for 10 base but for 11-12-13-14-15 . . . base I'm not able. Have you some solution?

Lilli
  • 91
  • 1
  • 8
  • Can you show us your try with `[0-9]`? Also, explain exactly where you have difficulties. And it would be helpful if you provide some small examples with desired output. – Zabuzard Dec 17 '17 at 19:27
  • I have used this code: https://ideone.com/3SCvZf I have modified it for my program, but I'm not able to have the result for another base. – Lilli Dec 17 '17 at 19:28
  • 1
    Please include the code in your question by **editing** and please try to create a [mcve] (removing irrelevant stuff). – Zabuzard Dec 17 '17 at 19:29
  • `but I am not able to do it for another base like 16` This question is _not_ a duplicate of [Using-regular-expressions-to-validate-a-numeric-range](https://stackoverflow.com/questions/22130429/using-regular-expressions-to-validate-a-numeric-range) which is base 10 centric. Please read the questions before marking duplicates. –  Dec 17 '17 at 20:42
  • It may or may not be so hard. Base 10 is 0-9, whereas base 16 is 0-9A-F. So, 6-2C (base 16) is something like `[6-9A-F]|1[0-9A-F]|2[0-9A-C]` if you catch my drift. –  Dec 17 '17 at 21:00
  • The input of the program are two numbers and the output is an regex to get all the number between the input numbers of the program. I'm able to do this for 10 base but for 11-12-13-14-15 . . . base I'm not able. Have you some solution? – Lilli Dec 17 '17 at 21:02
  • I think the base 16 example should get you started on the other bases, just realize regex is _character_ oriented, octal for example might be 0-7. The formulae is of course 0-base, 0-base 0-base, etc.. as each column represents the min/max for that position. The trick is to trim the regex to match the limits (ie: begin and end) to match your input. –  Dec 17 '17 at 21:04

1 Answers1

1

For base 16 numbers, use

[0-9A-F]
Josh Withee
  • 9,922
  • 3
  • 44
  • 62
  • The input of the program are two numbers and the output is an regex to get all the number between the input numbers of the program. I'm able to do this for 10 base but for 11-12-13-14-15 . . . base I'm not able. Have you some solution? – Lilli Dec 17 '17 at 20:59