On 10/16/07, Kevin Viel <[EMAIL PROTECTED]> wrote: snip > > If the first field can be just a dot too, consider this: > > > > s/ (\A|,) [.] (?=,|\z) /$1/xg > ^ ^ ^ ^ > > (if you chomp first :) > > Thank you kindly for your response. Are the spaces, which I highlighted > with carrots, the whitespace (or comment) allowed by the /x? If so, is the > function of the () and [] to delineate the content? How might it appear > without the /x? > > What part of this is saved in $1? > > Do you qualify the use of chomp since you used \z? snip
The \z character class does not match newline chacters, so, yes, you need to chomp the string if your are going to use this regex. The spaces are not part of the match due to the usage of the x option. They are there to make the regex easier to read. The x option does not change the meaning of parenthesis () or brackets [], so the first capture is either the beginning of the string (in the case of ",1,2,3") or the comma before a field with only ".". The second set of parenthesis are not capturing parenthesis, they are part of the zero-width positive look-ahead assertion. When a question mark is the first character inside a set of parenthesis it means that it is not a capture group, but rather one of the special groups. The brackets are being used because some people find [.] easier to read than \.. Without the x option it would look like s/(\A|,)[.](?=,|\z)/$1/g -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/