P
Prabh
Hello all,
I traverse through a file, line-by-line and try to change the path in
a string which holds path, e.g., if the string is, "File is at
C:\AppFolder\Folder1\Foo.txt", I'm trying to change Folder1 to
Folder2, i.e.,
From: "C:\AppFolder\Folder1\Foo.txt"
To: "C:\AppFolder\Folder2\Foo.txt"
Trouble is, I cant even check to see if the string has a match to
"C:\AppFolder\Folder1....", I suspect because of the backslashes.
The relevant piece of code:
=====================================================================
String getLine = "File is at: C:\AppFolder\Folder1\Foo.txt" ;
PatternCompiler compiler = new Perl5Compiler() ;
Pattern pattern = compiler.compile(getLine) ;
PatternMatcher matcher = new Perl5Matcher() ;
if ( matcher.matches(getLine, pattern ) )
{
System.out.println("Its a match!") ;
} else {
System.out.println("It couldnt match!") ;
}
=====================================================================
As you can see, I am basically matching a string against itself, just
to get going in the java regex learning process. I cant even match a
string to itself much less do a substitution on it.
Could some one give me some pointers on how to match and substitute
Folder1 with Folder2 ?
Thanks for your time,
Prabh
I traverse through a file, line-by-line and try to change the path in
a string which holds path, e.g., if the string is, "File is at
C:\AppFolder\Folder1\Foo.txt", I'm trying to change Folder1 to
Folder2, i.e.,
From: "C:\AppFolder\Folder1\Foo.txt"
To: "C:\AppFolder\Folder2\Foo.txt"
Trouble is, I cant even check to see if the string has a match to
"C:\AppFolder\Folder1....", I suspect because of the backslashes.
The relevant piece of code:
=====================================================================
String getLine = "File is at: C:\AppFolder\Folder1\Foo.txt" ;
PatternCompiler compiler = new Perl5Compiler() ;
Pattern pattern = compiler.compile(getLine) ;
PatternMatcher matcher = new Perl5Matcher() ;
if ( matcher.matches(getLine, pattern ) )
{
System.out.println("Its a match!") ;
} else {
System.out.println("It couldnt match!") ;
}
=====================================================================
As you can see, I am basically matching a string against itself, just
to get going in the java regex learning process. I cant even match a
string to itself much less do a substitution on it.
Could some one give me some pointers on how to match and substitute
Folder1 with Folder2 ?
Thanks for your time,
Prabh