English 中文(简体)
“C:/”的定期表述
原标题:Regular Expressions for "C:\"
  • 时间:2011-02-25 22:36:00
  •  标签:
  • java
  • regex

我试图找到能够找到“C:/”。

我的法典是:

String test = "C:\";  
String regex = "[a-z]*[A-Z]*[:]*\";  
if(test.matches(regex))  
    System.out.println("Success!");  
else  
    System.out.println("Failure!");  

I m 正在获得SyntaxException。 我用许多定期的措辞进行了审判,结果也是一样的。

我如何解决这一问题?

问题回答

简单(但可能是无用的)答案是“......”。

在此情况下,你显然希望更接近:[a-zA-Z]:。 这完全需要一封信,然后是上校,然后是回击。 假设你的扼杀本应代表视窗上某些磁盘的根基,它应当比你在任何情况下的更接近。

顺序在大多数语文中具有特别的意义。 正因为如此,它选择了一条道路。 您在此提出的问题是,它具有特别的意义,具有定期表达。 也就是说,在常规表述中,>_______________________________________ 。

BTW 我认为,你们需要的是“[a-zA-z]:吗?”

OMG对SO也有特别意义:P

你们需要把越狱一度,一度是 Java的越狱,一度是reg的越狱:

String test = "C:\";
String regex = "[a-zA-Z]:\\";
if ...

If you are trying to find C: explicitly, you could just use String regex ="C:\"; Not very flexible, but fits exactly.

What you are likely looking for is something like String regex = "[A-Z]:\\"; That says to "Match a single character in the range between "A" and "Z"" then "Match the character ":"" then "Match the character ". If you need to include lowercase beginning letters use String regex = "[a-zA-Z]:\\"; which matches a single character either between "a" and "z" or between "A" and "Z".

为什么不只使用<代码>String.contains ("C:/”)?





相关问题
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 ...

热门标签