RE: REGEX
"M Habibi" <[email protected]> Wed, 14 May 2003 16:28:09 -0400
| Newsgroups | gmane.comp.jakarta.oro.user |
|---|---|
| Message-ID | <[email protected]> |
Neil,
According to your original message, it does seem to be what you want. That
is, the characters 'b',followed by 'o', followed by 'o', followed by 'k',
followed by '\'. The issue here is twofold, so it's a little tricky. The
first part is the String representation of book\. That is, to represent
'book\' as a String, you need to write following
String candidate = "book\\";//-->outputs as book\
This has nothing to do with regex, and is simply a Java matter: If you
didn't do this, you couldn't compile your code, because you would have the
following
//WRONG
String candidate = "book\";
This is the same reason that you can't simply write
//ALSO WRONG
String candidate = "\";
The second issue is that you're trying to tell the regex engine that you
need it to check for the pattern. Here, you have a regex issue, in addition
to a straight java issue. Hence, the need to have quadruple \ characters.
Try the following: It's jdk 1.4 regex, but the patterns should be
consistent.
String candidate = "book\\";
boolean isMatch = candidate.matches("book\\\\");
System.out.println("isMatch = " + isMatch);
System.out.println("candidate = " + candidate);
//now try reading it in from the file book.txt.
//the sole entry in book.txt should be book\
FileInputStream fis = new FileInputStream("book.txt");
byte line[] = new byte[5];
fis.read(line);
candidate = new String(line);
isMatch = candidate.matches("book\\\\");
System.out.println("isMatch = " + isMatch);
System.out.println("candidate = " + candidate);
HTH,
M
-----Original Message-----
From: Neil Merin [mailto:[email protected]]
Sent: Wednesday, May 14, 2003 3:19 PM
To: M Habibi
Cc: Neil Merin
Subject: RE: REGEX
This results in book\\ as my pattern which is not what I want.
Thanks,
Neil
-----Original Message-----
From: M Habibi [mailto:[email protected]]
Sent: Wednesday, May 14, 2003 3:08 PM
To: [email protected]
Subject: RE: REGEX
I meant that the quotes weren't part of the regex: they are part of the
string. I can see how that's confusing.
Your full string should be
String regex = "book\\\\";
-----Original Message-----
From: Neil Merin [mailto:[email protected]]
Sent: Wednesday, May 14, 2003 2:53 PM
To: M Habibi
Cc: Neil Merin
Subject: RE: REGEX
Without the quotes I get a compilation error.
linePattern1 = lineCompiler.compile(books\\\\);
D:\users\merin\perf>C:\jdk1.3.1_07\bin\javac.exe -classpath
D:\users\abaqus60\IA-resources\Jakarta\customcode.jar;D
:\users\merin\perf ModifyRegistry.java
ModifyRegistry.java:22: illegal character: \92
linePattern1 = lineCompiler.compile(books\\\\);
^
ModifyRegistry.java:22: illegal character: \92
linePattern1 = lineCompiler.compile(books\\\\);
^
ModifyRegistry.java:22: illegal character: \92
linePattern1 = lineCompiler.compile(books\\\\);
^
ModifyRegistry.java:22: illegal character: \92
linePattern1 = lineCompiler.compile(books\\\\);
^
ModifyRegistry.java:22: cannot resolve symbol
symbol : variable books
location: class ModifyRegistry
linePattern1 = lineCompiler.compile(books\\\\);
^
5 errors
-------------------
With the quotes I get --> books\\ as my pattern.
linePattern1 = lineCompiler.compile("books\\\\");
D:\users\merin\perf>C:\jdk1.3.1_07\bin\java.exe -classpath
D:\users\abaqus60\IA-resources\Jakarta\customcode.jar;D:
\users\merin\perf ModifyRegistry
books\\
------------------
Now how can I get --> books\ ???
linePattern1 = lineCompiler.compile("books\\");
D:\users\merin\perf>C:\jdk1.3.1_07\bin\java.exe -classpath
D:\users\abaqus60\IA-resources\Jakarta\customcode.jar;D:
\users\merin\perf ModifyRegistry
Exception in thread "main" java.lang.NullPointerException
at ModifyRegistry.main(ModifyRegistry.java:26)
Neil
-----Original Message-----
From: M Habibi [mailto:[email protected]]
Sent: Wednesday, May 14, 2003 2:36 PM
To: ORO Users List; [email protected]
Subject: RE: REGEX
try "book\\\\" no quotes.
HTH,
M
-----Original Message-----
From: Neil Merin [mailto:[email protected]]
Sent: Wednesday, May 14, 2003 2:13 PM
To: [email protected]
Cc: Neil Merin
Subject: REGEX
I am having problems creating a simple regex pattern that would match the
string
'books' followed by a backslash '\'.
In other words 'books\' without the ticks. This appears to be a simple
pattern but I am having problems. I've tried to create a simpler pattern
that would match a single backslash but had no luck.
linePattern1 = lineCompiler.compile ("books\\");
String test = linePattern1.getPattern(); # line 25
# Runtime Error #
Exception in thread "main" java.lang.NullPointerException
at ModifyRegistry.main(ModifyRegistry.java:25)
Any suggestions on creating patterns with backslashes.
Thank you,
Neil
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]