Finnbarr Murphy schrieb:
All,
Is the output from the following test script correct?
#!/usr/bin/ksh93
echo ${.sh.version}
var='A regular expressions test'
echo "1> //e/#"
echo ${var//e/#}
echo "2> //[^e]/#"
echo ${var//[^e]/#}
echo "3> //+(e)/#"
echo ${var//+(e)/#}
echo "4> //-(e)/#"
echo ${var//-(e)/#}
echo "5> //?(e)/#"
echo ${var//?(e)/#}
echo "6> //*(e)/#"
echo ${var//*(e)/#}
echo "7> //!(e)/#"
echo ${var//!(e)/#}
The output is:
Version M 1993-12-28 s+
1> //e/#
A r#gular #xpr#ssions t#st
2> //[^e]/#
###e######e###e########e##
3> //+(e)/#
A r#gular #xpr#ssions t#st
4> //-(e)/#
A regular expressions test
5> //?(e)/#
###########################
6> //*(e)/#
###########################
7> //!(e)/#
#
Note the extra "#" in test 5 and 6 while test 7 only outputs a single "#"
Is there a simple explanation?
I'm not sure about 5) and 6). The following simplified test case yields
a single '#':
var=
print ${var//?(e)/#}
The pattern means "zero or one 'e'", and it appears that ksh interprets
an empty string as "zero 'e'". Thus the string matches the pattern and
gets replaced by a '#'. This would also explain the extra '#' in your
test. One could argue about that; bash, for example, prints an empty
string here.
7) is correct. The longest substring not representing a single 'e' is
the string itself, so the complete string is replaced by a single '#'.
Regards,
Bernd
--
Bernd Eggink
[EMAIL PROTECTED]
http://sudrala.de
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users