RE: Problem with start of line "^" RE and subst

"Rui Duarte" <[email protected]> Tue, 25 Feb 2003 10:25:03 -0000
Newsgroups gmane.comp.jakarta.regexp.user
Message-ID <[email protected]>
Hi.
The problem is that the '^' implicitly matches the first char, so when you call subst it replaces that first char with the expression.
One possible solution is to keep that first char so you can add it to the end of the replacing text:
 ...
	motor2 = new RE("(^.)");
	motor2.match("test.me");
	// get the expression inside parens
	String firstChar = motor2.getParen(1);
	// add it to the replacing text
	String out = motor2.subst("test.me", "http://" + firstChar);
	System.out.println(out);
 ...
	Out:

      http://test.me

Rui Duarte

-----Original Message-----
From: [email protected] [mailto:[email protected]] 
Sent: terça-feira, 25 de Fevereiro de 2003 9:05
To: [email protected]
Subject: Problem with start of line "^" RE and subst 


Hi!

I have the problem that I receive urls without "http://" part, so I used 
"^" as match and "http://" as replacement in RE.subst

No that I call myre.subst("test.me","http://") it comes out as 
"http://est.me" and the "t" is missing. 

What's wrong? 

Harry

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]