Reputation: 33
I'm using notepad++ and I'm trying to edit objects from a script that have spaces in them. The specific lines would start with "edit".
edit test-object-1
set subnet 1.1.1.1 0.0.0.0
next
edit test-object-2
set subnet 1.1.1.1 0.0.0.0
next
edit test object 3
set subnet 1.1.1.1 0.0.0.0
next
edit test-object-4
set subnet 1.1.1.1 0.0.0.0
next
edit test-object-5
set subnet 1.1.1.1 0.0.0.0
What I would like to do is replace the spaces in "test object 3" to "test-object-3"
So far it seems that I would start with something like ''' "^edit\s" ''' but I'm getting stuck at being able to search only words that contain a \s between words. Any help on finding and replacing in notepad would be appreciated and I'm sure it's something simple too :(
Upvotes: 3
Views: 162
Reputation: 163632
You could use
(?:\G(?!^)|^edit\h)\S*\K\h+
Explanation
(?:
Non capture group
\G(?!^)
Assert the position at the end of the previous match, but not at the start of the string|
Or^edit\h
match edit at the start of the string followed by a horizontal whitespace char (according to the comment))
Close group\S*
Match 0+ non whitespace chars\K\h+
Clear the match buffer (forget what is matched until now) and match 1+ horizontal whitespace charactersIn the replacement use -
Upvotes: 2