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?
Try with following regex:
(\d+\.\d+),(\d+\.\d+)
and replace it with:
\2,\1
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..
Make sure you place the cursor at the beginning of the file.
Hit CTRL+H.
Choose the Replace tab.
Select Regular Expression at the bottom.
Find: ([\d.]+),([\d.]+)
Replace: \2,\1
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.
Related
In the example below, is there any way to place a string like ("1one1") before {",} at the end of all lines which contain {ī}?
īn:"ZZin",
ín:"FFin",
ǐn:"QQin",
ìn:"TTin",
ie:"XXie",
iē:"TTie",
ié:"GGie",
Thanks
Using Notepad++ regex search for ^(.*ī.*)(",)$ and replace with \11one1\2.
You will need to use regex regex for notepad++.
so, mark "Regular Expression" in the final of Replace box.
in your fields to search:
find what: ī.[^"]"([A-Za-z0-9]*)
replace with: īn:"\11one1
i think it will do what you want. Let me know if it doesn't to edit the regex.
I have to make changes to URL's in a couple of notepad files. I was hoping if this could be done using regular expressions.
The URL's are in the following structure,
/web/20120730114452im_/hxxp://mysite1.com
/web/20120730114453im_/hxxp://mysite2.com
/web/20120730114454im_/hxxp://mysite3.com
/web/20120730114454im_/hxxp://mysite4.com
I have to remove the part before the hxxp so what remains after the search and replace is,
hxxp://mysite1.com
hxxp://mysite2.com
hxxp://mysite3.com
hxxp://mysite4.com
What is the regular expression I need to use to get the desired result ?
Thanks for your help.
Okay, as per your confirmation, a proper regex that won't match too much would be this:
/web/[0-9]+im_/
Where [0-9]+ will match any amount of numbers.
regex101 demo.
Don't forget to check the 'regular expression' checkbox in the Find/Replace dialog box.
USE THIS,
FIND: [ a-z 0-9 _ / ]+/hxxp
REPLACE: hxxp
I'm using Dreamweaver on a file that has about 30 instances the following:
'portfolio_bg' =>'#555555',
'portfolio_font'=>'#ffffff',
But, for each instance the hex codes are different. I want to add the following two lines underneath the above:
'product_bg' =>'#555555',
'product_font'=>'#ffffff',
where the hex codes in my two product lines will match the hex codes of the portfolio lines above it.
How do I accomplish his using regular expressions in Dreamweaver's Find and Replace?
Thanks in advance.
This works for me in EditPad Pro; it should work in Dreamweaver too.
Find:
'portfolio_bg'\s*=>\s*'(#[0-9A-Fa-f]+)',(\s+)'portfolio_font'\s*=>\s*'(#[0-9A-Fa-f]+)',\s*
Replace:
$&$2'product_bg' =>'$1',$2'product_font'=>'$3',$2
EDIT: corrected replacement string to use $& instead of $0.
For the first line, use the following RegEx replacement:
Find:
'portfolio_bg'[ \t]*=>[ \t]*'(#[0-9]{6})',
Replace:
'portfolio_bg' =>'\1',\n'product_bg' =>'\1',
For the second line,, use the following RegEx replacement:
Find:
'portfolio_font'[ \t]*=>[ \t]*'(#[0-9a-f]{6})',
Replace:
'portfolio_font' =>'\1',\n'product_font' =>'\1',
In Notepad++, how do you Find and Insert (instead of Find and Replace) while using a regular expression as the search criteria?
For non regular expression, you can simply include what you are finding in the replace value, but for regular expression, that won't work. Ideas?
very simple, if you need to add some text to every match of your search you can use backreferences in regular expressions, so for example, you have:
this is a table.
and you want to get "this is a red table",
so you do search for:
(this is a)
and replace with (in regular expression mode):
\1 red
also note, that we've used parenthesis in our search. Each set of parens can be accessed in replace with the corresponding \N tag. So you can, for example search for
(this is).*(table)
and replace it with
\1 not a \2
to get "this is not a table"
Dmitry Avtonomov answered it right but I just wanted to add in case you have something dynamic in between two strings.
Example:
Line 1: Question 1
Line 2: Question 2
And you want to just add a dot after the end of each question number, you can add at this way.
In Notepad++
Replace : (QUESTION)(.*)(\r\n)
With : \1 \2. \3
Result:
Line 1: Question 1.
Line 2: Question 2.
Have you checked other posts?
Maybe this will help you get your answers:
Using regular expressions to do mass replace in Notepad++ and Vim
http://markantoniou.blogspot.com/2008/06/notepad-how-to-use-regular-expressions.html
I have
2,5-3,5
3,5-4,5
...
and want
2.5-3.5
3.5-4.5
My "Find what" in Replace look like
[0-9],[0-9]
But I cannot make "Replace with"
\2.\1 to work. Nor does $2.$1.
This is clearly a simple task. What am I doing wrong?
Thanks
You need to specify groups to use replacement tags. I don't use notepad+, but if it's similar to other regex implementations \([0-9]\),\([0-9]\) should do the trick.
Did you checked Regular Expression checkbox(Search mode) in Notepad search and replace dialog?
I have just tried, this will work just fine for your case.
Search string: (\d),(\d)
Replace string: \1.\2
If you want to be more precise you can search and replace like this
Search string: (\d),(\d)-(\d),(\d)
Replace string: \1.\2-\3.\4
End just for reminder here is picture where you have to check regular expression option