Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Regex and java... not fun, help? (links and stuff)  (Read 608 times)
0 Members and 1 Guest are viewing this topic.
Offline Sequalit

Junior Member





« Posted 2006-04-21 06:57:52 »

Im trying to implement a regex for my game, my target is to read a file, and get relative links (they look like this : C:\\windows\blah\blah)
and i want to replace all of the " \ " with " / " so it looks like (C://windows/blah/blah)

the problem i run into is java is throwing this nasty error:

1  
2  
3  
4  
5  
6  
7  
java.util.regex.PatternSyntaxException: Unexpected internal error near index 1
\
 ^
   at java.util.regex.Pattern.error(Unknown Source)
   at java.util.regex.Pattern.compile(Unknown Source)
   at java.util.regex.Pattern.<init>(Unknown Source)
blah blah


so, obviously it doesntl ike my regex  code, here it is

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
for(int i=0;i<fileLines.size();i++){
            String tmp = (String)fileLines.get(i);     //file lines is an arraylist of strings
//which is relative to the lins of the file
           String one = "\\";
            char o = 92;
            System.out.println((int)'\\');
            System.out.println(one+"HELLOWORLD");
            System.out.println("TTTTTTTTTTTTTTTTTTTTTTTT"+tmp);
            tmp.replaceAll(""+o, "/");
            System.out.println("TTTTTTTTTTTTTTTTTTTTTTTT"+tmp);
            //tmp.replaceAll("\\", "\\"+"\\");
           fileLines.set(i, tmp);
         }


can anyone tell me what im doig  wrong and how to fix it?

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2006-04-21 07:33:15 »

There are two levels of escaping that you need.  One to make a backslash character in a Java string ("\\" is written in source code to get a string object with a single backslash)... and then you need two of those so the final regex string has two backslashes so the regex backslash is escaped with a backslash... clear as mud?

I think you are looking for something like this:

String blah 2 = blah.replaceAll("\\\\","/");

Offline Sequalit

Junior Member





« Reply #2 - Posted 2006-04-21 07:38:56 »

I figured it out...


i forgot to do this

1  
tmp = tmp.replace('\\', '/');


dont you hate it when your mistake is soooo simple and you think its something really complex?

while(gettingTired())
     crankOutMoreCode();
     if(asleep()){
          wakeUp();
          makeCoffee();
          chugCoffee();
     }
}

-Sequalit
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Mr_Light

Senior Member




shiny.


« Reply #3 - Posted 2006-04-22 21:02:37 »

 File.seperator ?


It's harder to read code than to write it. - it's even harder to write readable code.

The gospel of brother Riven: "The guarantee that all bugs are in *your* code is worth gold." Amen brother a-m-e-n.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (75 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (165 views)
2014-04-08 23:06:04

tom_mai78101 (261 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!