Originally posted by adithi gudipudi:
Max,
String tmp = "ab test hello all ab test1" ;
String s = tmp.replaceAll("[^a^b^ ]","X");
why do we need ending ^ in the regular expression. the ^a would be for not A ^b would be for not b then ending ^ for ???
thanks for your help!!
Adithi.
"I'm not back." - Bill Harding, Twister
Originally posted by Jim Yingst:
[B][adithi]:
[b][Max]:
[/B]
That doesn't seem to fit the requirements. Note that "all"
becomes "aXX",
contrary to adithi's example.
You're right, I misread her example.
Also, does [^a^b^ ] do anything different from [^ab ]?
Not really, though it's a hair more efficient.
I'll give the original pattern some thought: it seems like
there should be a simpler solution.
All best,
M
[ April 25, 2004: Message edited by: Max Habibi ]
"I'm not back." - Bill Harding, Twister
I struggle about the ".*?". Isn't it the same as ".*" ?
No, the ? make a big difference - it tells the matcher to always find the
shortest match (starting at wherever the first "<" is). This
is exactly what we need here, ensuring that if we process something like
"I'm not back." - Bill Harding, Twister
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|