English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

My goal is to replace any series of spaces (ie. " ", " ", " ", and so on) to this: " =$A$"

Here's my code to pull that off:
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Space
{
public static void main( String args[] )
{
Pattern spacePattern = Pattern.compile( "[ ]+" );
String exchange = " =$AS";
String output = spacePattern.matcher( " 1 2 3 4" ).replaceAll( exchange );
System.out.println( output );
}
}

It compiles just fine, but upon execution, you get this:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
at java.util.regex.Matcher.appendReplacement(Matcher.java:561)
at java.util.regex.Matcher.replaceAll(Matcher.java:661)
at Space.main(Space.java:11)
It appears the '$' in the replaceAll argument is the culprit but I need it for my work. Any help?

2006-09-09 12:12:57 · 5 answers · asked by Scott 1 in Computers & Internet Programming & Design

5 answers

The $ (dollar sign) symbol needs to be escaped. The escape character is the "\" (backslash). Since that is also a special character, it needs to be escaped itself.

So the answer is to use this:
String exchange = " =\\$AS";

2006-09-10 20:50:48 · answer #1 · answered by vincentgl 5 · 0 0

Java makes use of issues called instructions, that are what you're making once you write code and various instructions incorporate the Java Runtime environment (which you have in case you have the java internet browser plugin). WHat this is asserting is a sort of instructions, which you named above, is lacking. the two the webhost is directing you to an application for which the class is now no longer recent or you dont have it on the gadget (yet based on the call, i think of its host factor). document it to the positioning in case you prefer to.

2016-11-07 00:13:04 · answer #2 · answered by rangnow 4 · 0 0

you might have not setup directory linking for include files.
check the java directory structure registry and setup properly.
That might help.

2006-09-09 12:55:04 · answer #3 · answered by Anonymous · 0 0

turn off error detection

2006-09-09 12:14:35 · answer #4 · answered by markshere4u 2 · 0 1

ahhhhh?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

2006-09-09 12:15:09 · answer #5 · answered by Anonymous · 0 0

fedest.com, questions and answers