Reputation: 968
I have a document with many lines in this format: text ........ text
, I want to replace these strings of '.'s with a single ','.
The regular expression .*.
doesn't seem to work, and I'm not sure why. Any suggestions would be great.
Upvotes: 2
Views: 1685
Reputation: 396
Could you try, find by regex: \.+
or \.{2,}
And replace by: .
Upvotes: 1
Reputation: 626794
A .*.
matches any 0+ chars othert than line breaks and then any char other than a line break.
You need
Find What: \.{4,}
Replace With: ,
The \.{4,}
will match 4 or more occurrences of consecutive dots.
Variations:
You may use \h+\K\.+(?=\h)
and replace with ,
if you need to require horizontal whitespace before and after 1+ dots and replace with ,
. Here, \h+
matches 1 or more horizontal whitespaces, \K
omits these whitespaces from the match, \.+
matches 1 or more dots, and then (?=\h)
positive lookahead tries to assert the presence of a horizontal whitespace after the last dot matched.
An equivalent of the above expression is (?<=\h)\.++(?=\h)
pattern (where (?<=\h)
positive lookahead is used to require a horizontal whitespace).
The same result can be achieved with capturing groups: search for (\h)\.+(\h)
and replace with $1,$2
.
Note that +
(one or more repetitions) in these patterns can also be replaced with the limiting quantifier {min,max}
, where max
parameter can be missing, just make sure you adjust its values as needed.
Upvotes: 3
Reputation: 726559
You need to escape the dot, because it is a metacharacter which matches any symbol.
You can literally escape it with backslash, like this, \.
or use a character class, like this [.]
.
For replacing sequences of dots of, say, 5 items or more, use [.]{5,}
Note: You can express "one or more x
" as x+
instead of x*x
to avoid repeating the content of x
Upvotes: 3