Bowe
Bowe

Reputation: 191

Regular expression to modify a line that contains only a single word at the start

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?

Upvotes: 2

Views: 117

Answers (1)

Kobi
Kobi

Reputation: 138037

Regex to find lines with a single word:

^(\w+)$

replace with:

^$1^

Upvotes: 3

Related Questions