Find and Replace with Regular Expressions (Regex): Software error or inadequate user? :-)



  • Hi,

    I have this text:
    FIELD ONE
    FIELD TWO
    FIELD THREE

    I want to replace “spaces” with “underscores”, but only when the “space” is only one and between words.

    I use this Regex:
    Find: ([A-Z]) ([A-Z])
    Replace: \1_\2

    If I use buttons with the sequence
    Find, Repl&FAgain (1), Repl&FAgain (1), Repl&FAgain (1)
    I obtain a strange substitution
    FIELD_ONE
    FIEL_WO
    FIEL_HREE

    Instead of
    FIELD_ONE
    FIELD_TWO
    FIELD_THREE

    It works with button sequence
    Find, Replace Rest
    or
    Find, Repl&FAgain (3)

    Is it a bug or I misunderstood anything?

    Danilo



  • Hello, @Danilo Schembri and All,

    Ah, you spoke of the TextFX plugin behavior ! Seemingly, when doing a step by step replacement, it does not update the values of group 1 and group 2, leaving them empty :-((

    But, why don’t you perform the native N++ replacement, instead ?

    • Open the Replace dialog ( CTRL + H )

    • SEARCH ([A-Z])\x20([A-Z])

    • REPLACE \1_\2

    • Select the Regular expression` search mode

    • Tick , if necessary, the Wrap around option

    • Click, once, on the Replace All OR several times on the Replace button

    You may use a simple space character, instead of the \x20 syntax

    Best Regards

    guy038



  • @Danilo-Schembri

    your regex works for me

    Find: ([A-Z]) ([A-Z])
    Replace: \1_\2
    `Search Mode: Regular Expression

    gives me

    FIELD_ONE
    FIELD_TWO
    FIELD_THREE

    if i press replace all (or repeatedly press replace)

    @guy038
    i think you ment:
    REPLACE \1\x5F\2 instead of REPLACE \1\x20\2


Log in to reply