Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place a dot before a letter

I need to put a dot before a letter in this type of strings

name of data set: V2

6K102 62D102 627Z102

I would like to get this:

6.K102 62.D102 627.Z102

I am using this regex:

mutate(V2 = gsub("^[A-Z]",'\\.', V2))
like image 628
onhalu Avatar asked Mar 03 '23 08:03

onhalu


2 Answers

If the string has to start with 1 or more digits followed by a char A-Z, you could use 2 capturing groups

^(\d+)([A-Z])

In the replacement use "\\1.\\2"

sub("^([0-9]+)([A-Z])", "\\1.\\2", V2)
like image 59
The fourth bird Avatar answered Mar 05 '23 15:03

The fourth bird


you could use sub("([A-Z])",".\\1", V2)

like image 44
Daniel O Avatar answered Mar 05 '23 14:03

Daniel O