1

I need to reformat a text file a bit in my Notepad++ and I have a text of this kind:

This is some example text. This is some example text. This is some example text.
- This is some example text.
-This is some example text.
- This is some example text.
- This is some example text.

So as you can see in above text there are two types of "-" preceeding text the one with the space after "-" and ones without it I need to find only the ones without sapce and add it in between "-" and the "text"

If I ran piece of code below

-[A-Za-z0-9]

it finds dash and first letter right after it, which is not useful as when I replace the text it changes this first letter which is always different (depending on what is written) so I need to find this and select only the "-" and then replace it with "- " unless there is better way.

0

2 Answers 2

1

For demonstration purposes:

Find what: -([A-Za-z0-9])(.+)
Replace with: - \1\2

The parentheses denote a capture group. In the Replace with line, you use backslash and the number of group to add it.

That said, what you really want to match for is a NOT group, like -([^\s]) (match where a dash isn't immediately followed by a whitespace).

0
1

Search for

-([^ ])

and replace with

- \1

[^ ] is a negated character class and matches everything but a space. This character is stored in \1 because of the brackets () around the pattern.

1
  • This method works great as well so thanks too :)), you guys are great! Commented Apr 13, 2012 at 22:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.