> On 30 Nov 2015, at 14:57, phgrosj...@sciviews.org wrote:
> 
> 
>> On 30 Nov 2015, at 13:09, Abhinaba Roy <abhinabaro...@gmail.com> wrote:
>> 
>> Hey,
>> 
>> worked like a charm! :)
>> 
>> Could you please explain about
>> 
>> sub("^([0-9]*).*$", "\\1", fields)
>> 
> 
> Yes.
> 
> sub() replaces substrings. The first argument captures the interesting part 
> of the string:
> 
> ^ = start of the string,
> 
> ([0-9]*) = capture of the interesting part of the string. [0-9] means any 
> figure from 0 to 9. * means 1 or more of these characters, and () is used to 
> capture the substring, 
> 
> .* = all the rest. Dot (.) means any character, and * means again one or more 
> of these characters,
> 
> $ = the end of the string.

Small correction:

* means zero or more characters

according to ?regex.

Berend

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to