Page 1 of 1

Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 06:06
by Maxsteinfeld
Hi
I need help with this:
i have a list with book-titles e.g.
Wempen,.Faithe.-.No.018.15.-.Office.-.2016.For.Seniors.For.Dummies
I want to replace all "." (dots) with " " space exept the dots between 2 digits should remain
so in my example the result should be:
Wempen, Faithe - No 018.15 - Office - 2016 For Seniors For Dummies
my first step solution:

Code: Select all

OutNameNoExt:= RegExReplace(OutNameNoExt, "[.]", " ")
generates
Wempen, Faithe - No 018 15 - Office - 2016 For Seniors For Dummies
that works so far ... but the partial result "018 15" is not wanted
what should i have to add to match, that the dots between 2 digits remain
pls help
greetz
Max

Re: Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 06:53
by swagfag

Code: Select all

str := "Wempen,.Faithe.-.No.018.15.-.Office.-.2016.For.Seniors.For.Dummies"
str := RegExReplace(str, "([0-9])\.([0-9])", "$1ZZZZ$2")
str := StrReplace(str, ".", " ")
str := RegExReplace(str, "ZZZZ", ".")
MsgBox % str

Re: Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 07:59
by Odlanir
Or:

Code: Select all

str := "Wempen,.Faithe.-.No.018.15.-.Office.-.2016.For.Seniors.For.Dummies"
str := RegExReplace(str, "(\d+\.\d+)|(\.)", "$1 ")
MsgBox % str

Re: Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 08:15
by swagfag
Odlanir wrote:
01 Apr 2019, 07:59
Or:

Code: Select all

str := "Wempen,.Faithe.-.No.018.15.-.Office.-.2016.For.Seniors.For.Dummies"
str := RegExReplace(str, "(\d+\.\d+)|(\.)", "$1 ")
MsgBox % str

Code: Select all

Wempen, Faithe - No 018.15  - Office - 2016 For Seniors For Dummies
;                          ^ naaah

Re: Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 08:27
by Odlanir
@ swagfag You're right!. It should be:

Code: Select all

str := RegExReplace(str, "(\d+\.\d+)\.?|(\.)", "$1 ")

Re: Help to replace "." (dots) with " " (space) in a string  Topic is solved

Posted: 01 Apr 2019, 08:38
by sinkfaze

Code: Select all

str :=	"Wempen,.Faithe.-.No.018.15.-.Office.-.2016.For.Seniors.For.Dummies"
MsgBox %	RegExReplace(str,"\.(?=\D)|(?<=\D)\."," ")

Re: Help to replace "." (dots) with " " (space) in a string

Posted: 01 Apr 2019, 08:58
by Maxsteinfeld
@swagfag
@Odlanir
@sinkfaze
Thx for the quick response and help
all 3 solutions works perfect :-)
regards
Max