I need to remove "" from the both ends of the line
"/home/srinath/junk/backup"
and to display like this /home/srinath/junk/backup
How can we achieve this in groovy ?
thanks in advance, sri..
I need to remove "" from the both ends of the line
"/home/srinath/junk/backup"
and to display like this /home/srinath/junk/backup
How can we achieve this in groovy ?
thanks in advance, sri..
You don't have to use a regex. If you always want to remove the first and last characters you can do this with
'"/home/srinath/junk/backup"'[1..-2]
Alternatively, to remove all double quotation marks use
'"/home/srinath/junk/backup"'.replaceAll'"', ''
You want to replace ^"|"$
with the empty string. The ^
and $
are the beginning and end of string anchors, respectively. |
is the alternation metacharacter.
These were tested on lotrepls.appspot.com
:
Groovy >>> println('"hello" "world"'.replaceAll('^"|"$',''));
hello" "world
Groovy >>> println('bleh'.replaceAll('^"|"$', ''));
bleh
Groovy >>> println(''.replaceAll('^"|"$', ''));
(blank)
As specified, replaceAll('^"|"$','')
removes only doublequotes at the beginning and end of the string, if they're there. Internal doublequotes, if there are any, will be left untouched.