English 中文(简体)
在 JFLAP 中工作的 IPIP 验证的正则表达式
原标题:Regular Expression for IP validation which works in JFLAP

我注意到我们程序程序员在我们的方案中使用的常规表达式,用于诸如

  • email address validation
  • IP validation
  • ...

与 Automata 中使用的正则表达式稍有不同(如果我没有弄错)

By the way I want to design an NFA and eventually a DFA for IP validation. I have found a lot of regular expression such as the following one:

(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

但我不能用JFLAP把它转换成NFA或DFA。

我该怎么办?

问题回答

您不需要直接转换正正则, 一旦您了解它想要做什么, 您就可以重写它 。

有效的 IPv4 地址是 4 个数字, 以小数点分隔。 每个数字可以是 0 到 255 。 Regex 并不在很宽的范围之内, 因此它看起来是那么的。 如果以 2 开头, 那么接下来的两个数字不能大于 5 个, 如果以 1 开始, 它们可以达到 9 个等 。

验证 Regex 的最好方法是将它与 . 分隔为分隔符,将字符串转换为数字,并检查其范围。

说到这里,你张贴的正文中没有任何非标准的东西。他们来得太简单了,我不明白为什么它不能像你们一样有效。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签