I'm new to java, but have programed some in perl.
In perl I could easy do things like:
This would output:
I have tried to do simular stuff in java, but I don't manage to collect the content of the paranteces.
I have tried using Pattern.comile and find and tried several other stuf. I maged to cauptare the complete regexp and getting the index values of start end end posision, but was not able to extract only the content of the paranteces.
Anyone that have an excample of how this is done?
Java has no built-in support for regular expressions, so you cannot write something like /blabla/ for a regular expression. Also, the syntax for regular expressions in Java is not exactly the same as in Perl, so you probably can't use the exact same regular expression. The API documentation of class java.util.regex.Pattern describes Java's regular expression syntax.
You wrote that you already tried something with class Pattern. Why exactly did that not work? Could you get the source code to compile? If not, then what was exactly the error that you got? Can you show us your Java code that doesn't work?
There is a useful section in the Java™ Tutorials, which you may or may not know about.
Joined: Jul 12, 2010
Yes, I looked at a tutorial of the java.util.regex, but did dot manage to find the way to capture the paranteces.
This is one excample of code that is compiling:
The input text have some text than a _ followed bye a number (several digits) ending with a . and some more text.
The %s contains the match of the complete regexp, so includes the starting _ and ending . outside the paranteces.
The %d gives the start index and %d.%n gives the ending.
From what I read \1 should give the first parantces, but aparantly Im not using it correct since it is not working.