Find/Replace Regular Expression Anomaly
Posted: Thu Apr 25, 2002 3:26 am
I wrote a Find/Replace Regular Expression to move the open curly brace ({) from the end of a line to the next line indented to line up with the first character of preceding line. But, it will not move any curly braces that are already on a line by itself. This is the search expression:
^\([ \t]*\)\([a-zA-Z0-9]+[^{]*\){[ \t]*\n
and this is the replace expression:
\1\2\n\1{\n
It works fine when I click on Replace Next and change all the occurrences one at a time. However, if I click on Replace All, it moves all the occurrences except the second line of two adjacent lines with a curly brace at the end.
For instance, using this code as an example,
public class Test {
public static void main(String[] args) {
if (args.length == 1) {
System.out.println( "arg[0] = " + arg[0] );
}
else {
System.out.println( "No args " );
}
}
}
It will move all the curly braces, except on the
public static void main(String[] args) {
line.
Why would this work doing it one line at a time using Replace Next but not using Replace All.
Thanks,
Jerry
^\([ \t]*\)\([a-zA-Z0-9]+[^{]*\){[ \t]*\n
and this is the replace expression:
\1\2\n\1{\n
It works fine when I click on Replace Next and change all the occurrences one at a time. However, if I click on Replace All, it moves all the occurrences except the second line of two adjacent lines with a curly brace at the end.
For instance, using this code as an example,
public class Test {
public static void main(String[] args) {
if (args.length == 1) {
System.out.println( "arg[0] = " + arg[0] );
}
else {
System.out.println( "No args " );
}
}
}
It will move all the curly braces, except on the
public static void main(String[] args) {
line.
Why would this work doing it one line at a time using Replace Next but not using Replace All.
Thanks,
Jerry