- ***Bottom-line: `sub` scans each cell and look at only the first match to replace it. Does not matter how much of the match was captured. Looks at matched and captured text the same way.***
- Here is an output with `gsub`
"PFf2" "PF" "PFs4" "PFs5" "PFs6" "PFPFPFPFPF"
- ***Bottom-line: `gsub` scans each cell and look at all the matches to replace them and then replace each match with substitution.***
Thank you for your patience this morning
@wibeasley
Here is the work on Regex101. Please forgive the amateur pattern of regex here:
Example on regex101
In-addition, in each cell, matches have also been captured except the last cell where only one match (out of 5) has been captured.
I want to get it right:
regex <- "(^\D\D\D\D)|-\D\D\D\D|(^\D+)3"
sub(regex, "PF", pax) gsub(regex, "PF", pax)
[1] "PFf2" "PF" "PFs4" "PFs5"
[5] "PFs6" "PF-podf-podf-podf-podf"
"PFf2" "PF" "PFs4" "PFs5" "PFs6" "PFPFPFPFPF"