Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

notepad++ reg expressions to swap two values

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?

like image 698
user3158123 Avatar asked Apr 23 '14 14:04

user3158123


People also ask

Can I use RegEx in Notepad?

Using Regex to find and replace text in Notepad++ In all examples, use select Find and Replace (Ctrl + H) to replace all the matches with the desired string or (no string). And also ensure the 'Regular expression' radio button is set.

How do I replace a character in notepad?

To replace text in Notepad, follow the steps below. Open the text file in Notepad. Click Edit on the menu bar, then select Replace in the Edit menu. Once in the Search and Replace window, enter the text you want to find and the text you want to use as a replacement.

How do I replace numbers in Notepad++?

"[0-9]+" will replace ANY NUMBERS!


2 Answers

Try with following regex:

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

and replace it with:

\2,\1
like image 168
hsz Avatar answered Sep 30 '22 10:09

hsz


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..

like image 40
Grzegorz Adam Kowalski Avatar answered Sep 30 '22 10:09

Grzegorz Adam Kowalski