Closed GoogleCodeExporter closed 9 years ago
Thanks for the suggestion, I will look into it for the next release.
Steven
Original comment by baker.st...@gmail.com
on 21 Jan 2010 at 2:04
I am having trouble implementing this feature. I am also having trouble finding
any
existing solutions in Java for this (even anything outside of Vim).
If you could help me implement this or point me in the direction of a useful
document
on implementing this, it would be greatly appreciated.
Otherwise, this will likely not make it for the next release.
Original comment by baker.st...@gmail.com
on 3 Feb 2010 at 1:46
If you pulled it off, you'd be the first java implementation I know of. I
ended up
handling the need for this in my own project by using the maven-exec-plugin to
offload the work to perl. I wonder if it would be possible to pull portions of
the
Perl source (http://www.cpan.org/src/README.html), port them into Java, and use
those? I'll let you know if I get inspired and have any luck with this.
Original comment by curtis.l...@gmail.com
on 3 Feb 2010 at 2:28
I gave perl-5.11.4.tar.gz from above CPAN site a quick look, and my gut feeling
is
that the good stuff is in regexec.c. A comment at the beginning of the file
seems to
back that up :). I'm afraid my C is far too rusty to really make heads or
tails of
it, though.
Original comment by curtis.l...@gmail.com
on 3 Feb 2010 at 2:38
Or, actually it looks like this might be supported in java's regex stuff
already:
http://www.exampledepot.com/egs/java.util.regex/Group.html
The exciting bit of code is this one:
{code}
CharSequence inputStr = "abbabcd";
String patternStr = "(a(b*))+(c*)";
// Compile and use regular expression
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(inputStr);
boolean matchFound = matcher.find();
if (matchFound)
{
// Get all groups for this match for (int i=0; i<=matcher.groupCount(); i++) {
String
groupStr = matcher.group(i);
}
}
{code}
Original comment by curtis.l...@gmail.com
on 3 Feb 2010 at 3:00
I'm not quite sure how the above code can help. I think I will need to parse
the token
into sub replacement tokens for this to take place.
Due to the complexity of this enhancement, it has not made the 1.3 release. I
will
continue to investigate this enhancement.
Otherwise, you are most welcome to solve this enhancement and submit the change.
Original comment by baker.st...@gmail.com
on 9 Feb 2010 at 10:27
The String.replaceAll() method should do the job (however, with a slightly
differnt syntax):
public class RegexpReplaceTest {
public static void main(String[] args) {
String regexp = "beginning(.*)middle(.*)end";
String replaceString = "b$2m$1e";
String testString = "beginning-stuff-middle-here-end";
// Prints "b-here-m-stuff-e"
System.out.println(testString.replaceAll(regexp, replaceString));
}
}
In Java regular expressions, back referencing is done using a "$" symbol and
there is no need to escape the braces.
Original comment by st.fer...@gmail.com
on 9 Jun 2010 at 4:43
Attachments:
I can confirm that the above works within this plugin with the above's
variables,
token: regexp
value: replaceString
file contents: textString
Thanks for the help st.ferstl.
Since this is already functional I will close this Issue.
Original comment by baker.st...@gmail.com
on 13 Jun 2010 at 1:09
Original issue reported on code.google.com by
curtis.l...@gmail.com
on 21 Jan 2010 at 1:05