我想知道怎么做 [英] I want to know how to do this

查看:82
本文介绍了我想知道怎么做的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不是作业,我只是想做某种练习。



我的问题是....!

例如:对于在java中使用正则表达式查找输入的数字是b / w 1到26或不是



Pattern.matches(([1-9] | 1 [0- 9] | 2 [0-6]),20) - >这是数字





在同样我想要RomanNumbers。



示例:对于使用java中的正则表达式查找输入的RomanNumbers是b / w 1到26或不是



---> ;;我想知道这怎么做LT< ---

i尝试了这个,

This is not assignment,am just trying to do certain practice.

My question is....!
example:For Numbers using regex in java to find input is b/w 1 to 26 or not

Pattern.matches("([1-9]|1[0-9]|2[0-6])", "20")-->this is for numbers


In the same way i want for RomanNumbers.

example: for RomanNumbers using regex in java to find input is b/w 1 to 26 or not

--->;i want know this how to do lt <---
i tried this,

System.out.println(Pattern.matches("([I-IX])", "X"));



但输入为单然后它显示真实和其他错误...



我尝试过:




but when the input is single character then it showing true and other false...

What I have tried:

example:For Numbers using regex in java to find input is b/w 1 to 26 or not

		Pattern.matches("([1-9]|1[0-9]|2[0-6])", "20")-->this is for numbers


In the same way i want for RomanNumbers.

example: for RomanNumbers using regex in java to find input is b/w 1 to 26 or not
            --->i want know this how to do lt<---




i tried this,
 <pre>System.out.println(Pattern.matches("([I-IX])", "X"));



但是当输入是单个字符时它显示为true而其他为false ...


but when the input is single character then it showing true and other false...

推荐答案

基本上,虽然你可以做到,但不要。正则表达式不是一个很好的价值比较工具,它是一个文本处理器,而不是一个智能助手。

如果你想知道某个值是否在某个范围之间,请使用TryParse将其转换为数字,相比之下。

同样,如果你想检查罗马数字,那么你需要为罗马数字写一个TryParse - 这不是微不足道的,当然也不是我认为的东西使用正则表达式。如果不出意外,调试正则表达式将是一场彻头彻尾的噩梦,在代码中执行相同的操作会让您访问代码调试器,这样您就可以随时查看到底发生了什么。

有一个看看这个:在C#中使用隐式转换解析罗马数字 - KeesTalksTech [ ^ ]]你将开始了解代码中的任务有多复杂。作为正则表达式?只是因为可以做某事,并不意味着它应该!
Basically, while you can do it, don't. Regex is not a good tool for value comparisons, it is a text processor, not an intelligent assistant.
If you want to know if a value is between a range, convert it to a number using TryParse, and compare that.
Similarly, if you want to check roman numbers, then you need to write a "TryParse" for roman numbers - and that isn't trivial and certainly not something that I'd consider doing with a Regex. If nothing else, debugging the regex would be a total nightmare, where doing the same thing in code gives you access to the code debugger so you can see exactly what is going on at any time.
Have a look at this: Parsing Roman Numerals using implicit casting in C# - KeesTalksTech[^] ] and you'll start to get an idea how complex a task it is in code. As a Regex? Just because something can be done, doesn't mean it should!


这篇关于我想知道怎么做的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆