Help with a Regex query



  • Hi there!

    I’ve understand that I can do multiple search&replace queries in this way:

    Search: (á)|(é)|(í)|(ó)|(ú)
    Replace: (?1Á)(?2É)(?3Í)(?4Ó)(?5Ú)

    Example:

    Before: árbol ácido
    After: Árbol ácido

    But how can I use this method if I need to add a precondition, such as line start and some punctuation before it?

    I’ve tried:

    Search: (^[—¿¡«]*?)[(á)|(é)|(í)|(ó)|(ú)] => Works!
    Replace: \1(?2Á)(?3É)(?4Í)(?5Ó)(?6Ú) => Doesn’t work…

    Example:

    Before: —¿árbol ácido?
    After: —¿rbol ácido?

    Any help?

    Regards.



  • I answer to myself.

    As Sebastias Proske told me, the solution is ‘to use a non-capturing group for mere grouping purpose, character class is the wrong tool here’.

    Search: (^[—¿¡«]*?)(?:(á)|(é)|(í)|(ó)|(ú))
    Replace: \1(?2Á)(?3É)(?4Í)(?5Ó)(?6Ú)

    Example:

    Before: —¿árbol ácido?
    After: —¿Árbol ácido?

    Regards!


Log in to reply