Search code examples
regexkate

How to replace Kate regular expression


I am using the Kate editor. Here is a minimal example that shows my problem:

I have a file with a bunch of occurrences of:

\command{stuff}

where stuff is some arbitrary string of letters. I want to replace this with

\disobey{stuff}

where stuff is unchanged. The regular expression:

\\command\{[a-zA-Z]*\}

matches such expressions. So I pull the replace dialog with CTRL-r, and enter

Find: \\command\{[a-zA-Z]*\}
Replace: \\disobey\{\1\}

So in the document, an actual instance is say,

\command{exchange}

and when I hit the replace button is changed to

\disobey{1}

In the Kate documentation: Appendix B: Regular Expressions, \1 should match the first pattern used. Is this indeed the correct syntax? I have also tried $1, #1, and various other things.


Solution

  • Wrap the value with ( ) to capture it as a group, so you can use it in your replace

    So change your find regex like this:

    \\command\{([a-zA-Z]*)\}
    

    and you should do fine.