notepad++ reg expressions to swap two values

2019-02-18 01:01发布

i'm trying to swap latitude and longitude values in notepad++ with regular expressions. i tried to search some guide on the web but i didn't understand how to do. i have a file in which there are: "longitude,latitude" and i want to get: "latitude,longitude" in each row

Example (with two rows):

   12.5164654350527,41.8919188281474
   12.5164650441393,41.891919097598

   becomes

   41.8919188281474,12.5164654350527
   41.891919097598,12.5164650441393

Which regular expression do i have to use?

4条回答
Juvenile、少年°
2楼-- · 2019-02-18 01:44

Search for:

([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?)

Replace with:

\2,\1

This catches numbers like 1, 1.1 but not 1. or .5. My previous regexp ([0-9]+.?[0-9]*),([0-9]+.?[0-9]*) would allow for 1..

查看更多
虎瘦雄心在
3楼-- · 2019-02-18 01:52

find what:

^([0-9]*\.[0-9]*),([0-9]*\.[0-9]*)$

replace with:

\2,\1

also, search mode should be set to regular expression

edit: escaped . as suggested in comments.

查看更多
smile是对你的礼貌
4楼-- · 2019-02-18 01:57

Make sure you place the cursor at the beginning of the file.

  1. Hit CTRL+H.
  2. Choose the Replace tab.
  3. Select Regular Expression at the bottom.

    Find: ([\d.]+),([\d.]+)
    Replace: \2,\1

查看更多
smile是对你的礼貌
5楼-- · 2019-02-18 02:03

Try with following regex:

(\d+\.\d+),(\d+\.\d+)

and replace it with:

\2,\1
查看更多
登录 后发表回答