Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Among the joys of KDE, Kwrite is surely noteworthy. Having regular expression support built in by default into text editor is probably one of the top 10 best ideas of all time. Since I often need to do a lot of finding and replacing, I have already begun to save a lot of time and hassle by using Kwrite.

Just one problem: I'm still a newbie at it. I suppose it's probably a lot like in sed, but anyway, I am matching stuff like

numbersdonot8
belongattheend0
ofwords2

using the simple regex [a-z][0-9]. How do I then tell kwrite to replace the text using the first part of the regex? Using [a-z] in the 'replace' box gives things like 'numbersdonot[a-z]' as a result. But I want,

numbersdonot
belongattheend
ofwords
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Try:

Find: ([a-z])[0-9]
Replace: \1

Parenthesis save content matched and can be used with expression \<number> depending of how many parenthesis used in the Find expression and its order from the beginning.

For example, if you wanted to change order between the letter and the number, would be:

Find: ([a-z])([0-9])
Replace: \2\1
share|improve this answer
    
today, the universe is a more beautiful place. –  ixtmixilix Dec 29 '11 at 15:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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