tags:

views:

33

answers:

1

I have a text file in which any line that starts with a single word and has no other characters after that should be enclosed inside caret characters.

For example, a line that contains only the following 6 characters (plus the newline):

France

should be replaced with a line that consists of only the following 8 characters (plus the newline):

^France^

Is there a Regular Expression I could use in the Find/Replace feature of my text editor (Jedit) to make these modifications to the file?

+2  A: 

Regex to find lines with a single word:

^(\w+)$

replace with:

^$1^
Kobi
I ended up with only the ^^ characters on those lines - the text on those lines was erased.
Bowe
I edited a few seconds after the original post and added `()` - does it still erase your line?
Kobi
Yes, thanks, now it makes the replacement correctly but adds two extra blank lines after each of those lines where there is a match. Is that avoidable?
Bowe
That is strange... It isn't matching any newlines. Maybe your `replace` has extra lines?
Kobi
Damn. Yeah, I just noticed there were extra newline characters that I couldn't see. Sorry. This works perfectly. Thanks a lot!!
Bowe