regular expression replace reserve part of the original string - regex

I want to replace the text
Tag="...",
with
<Header="...", Style=Something>
while reserving the ... part. Can I do it with regular expression or some features of Sublime Text? Thanks!

Yes if you prefer. Use Ctrl + H to open the Search and Replace, enable Regular Expression..
Find What: Tag="([^"]+)",
Replace With: <Header="\1", Style=Something>

For content like this:
Tag="this is a \"simple\" test",
pattern: Tag="((?>\\.|[^"])*)",
Replace: <Header="\1", Style=Something>

Related

how to simulate a backspace in notepadd ++ regex

i have this txt
02/02
z/2019
i want it to look like this
02/02/2019
how can i achieve this using notepad++ regular expression function
This is possible with the "Extended" syntax only, you don't even need regular expressions.
Find: \r\nz
Replace:

In Notepad ++: Replacing some string with something else in all the lines containing another string

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.

Switching values

I am struggling with a generic regex to switch values around.
I want a quick way to rearrange
{"AAA","AA1"},
into
{"AA1","AAA"},
ideally using notepad++
Cheers.
Open Replace with Ctrl+H & tick the Regular Expression box
Find: \{(.*),(.*)\}
Replace With: {\2,\1}
(Assumes no } in the quoted values)
in notepad++ :
find :
\{\s*\"(.*?)\"s*\,\s*\"(.*?)\"\s*}
replace by :
{"\2","\1"}
Try this one:
Search: (\{\s*")([^"}]*)(",\s*")([^"}]*)("\})
Replace: \1\4\3\2\5
Pattern: \{("[^"]*")\s*,\s*("[^"]*")\}
Replacement: {$2,$1}
Explanation:
group the "..." parts
use the inverse character class [^"]* to match everything until the first "
reverse their orders with the backreferences: {$2,$1}

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

Replace using Regex

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