Can somehow automatically replace with this outcome:
INITIAL:
"eye","doc":441,"engagement":35877,"impression":1987869,"reach":294757,"repost":441}}
OUTCOME:
{"emojiAnnotations":{"eye","doc":441,"engagement":35877,"impression":1987869,"reach":294757,"repost":441}}
When "eye" and so on are variables....(only titles are the same)??
I thought to use - something like - "*","doc" replace (as an expression) with {"emojiAnnotations":"*","doc", but this will not keep variable "eye" and so on.
P.S. This is part of replacement process so to add at the beginning is not acceptable
Is this OK for you?
Ctrl+H
Find what: "[^"]+","doc"
Replace with: {"emojiAnnotations":{$0
check Wrap around
check Regular expression
Replace all
Explanation:
"[^"]+" : 1 or more not quote beweeen quotes
,"doc" : literally
Replacement:
{"emojiAnnotations":{ : literally
$0 : the whole match
Result for given example:
{"emojiAnnotations":{"eye","doc":441,"engagement":35877,"impression":1987869,"reach":294757,"repost":441}}
Related
I would like to find the third occurrence of string inside quotes in order to replace this string or part of this string. This is a typical line I have to deal with:
"/activities/absenceactivity/lang/#LANG_ID#/prop_dialog.php";"BA2_PD_SCR";"Opis
dogodka";"Event description";"Descrição do Evento";"ÐпиÑ
подÑÑ";"";"č®vykio aprašymas";"Descripción del evento";"";
I know that "([^"]*)" shows every occurrence of text and quotes but I would like to get just the third one, in this example "Opis dogodka" in order to perform Search & Replace in Sublime Text.
Problem is to find the third occurrence of string within the quotes, replace it entirely or just partially and make sure that the Regex provides also a solution for an empty
""
strings.
Thank you.
I'm sure there are ways to simplify this further, but if you're ok with brute force:
Sublime command:
Find: "[^"]*";"[^"]*";"([^"]*)".*
Replace: $1
NP++:
Find what: "([^"]*)";"([^"]*)";"([^"]*)".*
Replace with: $3
sed:
sed 's/"\([^"]*\)";"\([^"]*\)";"\([^"]*\)".*/\3/'
You can use {} pattern repetition:
/(?:"([^"]*)";){3}/ # first match group will be 'Opis dogodka'
Demo
Or, use a global type match and then take the third match. This might require logic such as slicing or looping:
/"([^"]*)";/g
Demo 2
Or, just manually put in the first two patterns to skip:
/^"[^"]*";"[^"]*";("[^"]*";)/
Demo 3
Or combine repetition to skip the first n-1 then capture the nth match:
/^(?:"[^"]*";){2}("[^"]*";)/
Demo 4
Let's say I wanted to replace something like this:
\section{Introduction}
with this:
<h1>Introduction</h1>
in notepad++.
Essentially, find and replace all the opening tags (in this case the "\section{" part) and closing tags (the "}") with different opening and closing tags,
Something like this. Except, of course, the text in between the tags stays the same. Is this possible within notepad++?
Find what: \\section\{(.+)\}
Replace with: <h1>\1</h1>
Here, the parentheses (.+) define a group that consists of one or more character, and \1 references the contents of the group.
Search :
\\section\{(.*)\}
And replace with :
<h1>\1</h1>
\1 will be replaced with your first regexp result.
I.e. searching :
\{(.*), (.*)\}
And replacing with :
[\1, \2]
Will transform {foo, bar} into [foo, bar] :
\1 = foo
\2 = bar
I've got a file with several (1000+) records like :
lbc3.*'
ssa2.*'
lie1.*'
sld0.*'
ssdasd.*'
I can find them all by :
/s[w|l].*[0-9].*$
What i want to do is to replace the final part of each pattern found with \.*'
I can't do :%s//s[w|l].*[0-9].*$/\\\\\.\*' because it'll replace all the string, and what i need is only replace the end of it from
.'
to
\.'
So the file output is llike :
lbc3\\.*'
ssa2\\.*'
lie1\\.*'
sld0\\.*'
ssdasd\\.*'
Thanks.
In general, the solution is to use a capture. Put \(...\) around the part of the regex that matches what you want to keep, and use \1 to include whatever matched that part of the regex in the replacement string:
s/\(s[w|l].*[0-9].*\)\.\*'$/\1\\.*'/
Since you're really just inserting a backslash between two strings that you aren't changing, you could use a second set of parens and \2 for the second one:
s/\(s[w|l].*[0-9].*\)\(\.\*'\)$/\1\\\2/
Alternatively, you could use \zs and \ze to delimit just the part of the string you want to replace:
s/s[w|l].*p0-9].*\zs\ze\*\'$/\\/
I have a string like this:
INSERT INTO `test` VALUES (999,'stuff',NULL,'2014-12-01 08:09:10');
What I want is remove some string to get the value between single quotes:
stuff
I've used 2 regex:
^.*\d,'
and
',NULL.*$
When I use count in Npp, it returns Count: 1 match., but when I use replace, it returns Replace: no occurrence was found.
Do you have any idea?
You just need to combine both regexes using | OR operator. Finally in the replacement part, you need to give an empty string, so that it would remove all the matched characters.
^.*\d,'|'.*$
OR
^.*\d,'|',NULL.*$
DEMO
OR
Find What: ^.*\d,'([^']*)',NULL.*$
Replace With : \1
DEMO
I have a set of words like this
"text1
"text2
"text3
which i need to convert to a quoted text which I was able to do with stackoverflow help like this
Find: ^\".*$
replace: $0"
There are another set of words like this
text1
text2
text3
which i need to convert to 1 quoted text which i was able to do
Find: ^(.+)$
Replace: "$0"
But in this case i was able to do it only by clicking replace all and not replace.
Can anyone tell why it's happening like this and How can I achieve this without using replace all and by using only replace?
Take care of the second replacement, it will replace "text1" by ""text1"".
Use this instead:
find what: ^[^"\n]+$
replace: "$0"
It should be working with Replace All and not Replace in any case. The function can also be affected by the position of the cursor and the direction to find/replace.
To be certain, you can place the cursor at the beginning of the file, ensure that the find direction is 'Down' and use Replace All.
Now to the regex, yes, you can do it in a single replace. Use this find:
^(?:")?(.*)$
And this replace:
"$1"
regex101 demo.
The (?:")? will consume the first double quote if present so that it isn't placed in the replace later on.
There's no way you used "Replace" only once in the first case! You must have pressed it 3 times (as many as your matches).
In both situations you need "Replace all", since you want multiple global matches. When pressing the "Replace all" button it's like using Perl's /g & /m modifiers in your substitution, you can experiment here to see what I mean.
BTW the use of a capture group (the parenthesis) is redundant in your 2nd example, use find: ^.+$ and replace: "$0".