Search code examples
regexnotepad++phpstorm

Is possible to 2-way replace in PhpStorm or Notepad++?


I have some CSS code in my document include left and right words.

I need to replace right => left and left => right.

Is possible in PhpStorm or Notepad++ to replace these words simultaneous ?


Solution

  • Using Notepad++

    • Ctrl+H
    • Find what: (right)|(left)
    • Replace with: (?1left:right)
    • check Wrap around
    • check Regular expression
    • Replace all

    Explanation:

    (right)     # group 1
    |           # OR
    (left)      # group 2
    

    Replacement:

    (?1         # if group 1 exists
        left    # replace with left
        :       # else
        right   # replace with right
    )
    

    Screen capture (before):

    enter image description here

    Screen capture (after):

    enter image description here