Select text and replace text with text + variable in Notepad++? - regex

Apologies, I am quite new to stackoverflow and not sure if this is a suitable question but I have already attempted to find the answer elsewhere
I have the line:
XYZ: "Text"
and am attempting to replace
XYZ: "Text"
with
XYZ: "Text (XYZ)"
is this possible with notepad++, it seems as though I need to select a variable within every line and then replace some text within the line with the text + (variable) can anyone think of a way to do this in Notepad++?
Note: The text on all lines is different and so is XYZ so I need it to be specific to each and every line

You can use this pattern for search (^[^:]*)(:[^"]*"[^"]*) and $1$2 \($1\) for replacement.
Demo

Related

regex help in notepad++ marking embedded values and copying into a new list

I have a large text file with numerous lines containing data like below.
205=1<SOH>55=ES<SOH>48=17875701615154475972<SOH>207=CME<SOH>100=XNYM<SOH>16552=1
205=155=6A48=17875736456456445774207=CME100=XNYM16552=1
I would like to extract all of the values that are after the "48=" and before the ASCII code 01 delimiter AND the same for the value after "55=" and paste them into a new file:
ES|17875701615154475972
6A|17875736456456445774
They aren't all 20 characters in length, so I would need to do a regex search to mark them all - can you help me with the right regex expression to use and how to copy the identified values out of notepad++?
Do a replacement on the whole file to leave only the targets:
Find: ^.*\b48=(\d+).*
Repl: $1
Then ctrl+a, ctrl+c and paste into a new file.
To answer the question in the comment about capturing "CME" and allowing both "55" and "48" as markers:
Find: ^.*?(?:48|55)=([\w;]+).*?=([A-Z]+).*
Repl: $2|$1
The following will match and create a group for the digits. <SOH>48=(\d*)<SOH>
However, what you probably want is a global search/replace that finds the numbers and rewrites the file. Try
Find: .*<SOH>48=(\d*)<SOH>.*
Replace: \1
Of course remember to check the Regular Expression box or it won't work at all.

Regex: for each /xxx.png go to next /yyy.eps and change it to /xxx.eps

I'd like to get a regex like so:
"for each /xxx.png go to the inmediately next /yyy.eps, and change it to /xxx.eps"
If possible, how could I do it with regex?
I'm working in a CSV file and using Notepad++.
Many thanks!
EDIT
Hoping this helps to clarify, a better example would be:
line 1: "landscape123.png","IwantToBeNamedlandscape123.eps"
line 2: "picture123.png","IdLikeToBeNamedpicture123.eps"
How can I take the pngs filenames and replace the next .eps filenames with them? Each time, both file types are on the same line.
Find:
^"(.*)\.png".*$
Replace with:
"\1.png","\1.eps"
This says: "Find lines that contain exactly: ", a filename (and capture the filename), .png", and then whatever; and then replace them with "\1.png","\1.eps"", where \1 is a backreference that contains the filename.
Make sure you have ". matches newline" unchecked.

How to create a newline above text that has a question mark?

I was wondering if anyone could help with this. I'm new to regex so I'm not sure exactly how to do this. I'm using Notepad++. Essentially what I want to do is every time there is an instance where there is a sentence ending with a question mark (?), I would like to create a new line above it.
E.g:
Junk text
Junk text
Junk text
Which of the following statements about the species diversity index is <strong>true</strong>?
I would like to appear like:
Junk text
Junk text
Junk text
Which of the following statements about the species diversity index is <strong>true</strong>?
Any one have any suggestions? Thanks in advance!
You could replace ^(.*\?) with \n\1.
^(.*\?) matches lines with a ?.
find: .*[?]$
replace with : \n$0
of course you need check the Regular expression button in replace tab.
You can do this:
Find and replace
Check regular expression checkbox at search mode
Search for : ^(.*)\?$
Replace with: \n\1?
Example:
a
b
c?
d
e?
f
Output:
a
b
c?
d
e?
f
With regex, you should replace
(.*)\?$
With
\r\n\1?
Does that do the trick?

notepad++ regex to replace define sort of data

I want to replace texts in huge text file using notepad++. I don't know how can I replace text only if it's length is between for example 50-100. As far as I know in regex it should look like this [a-zA-Z0-9 -+]{50,100} but it doesn't work in n++. I'm not a regex specialist.
Example input:
<a>short text</a>
<a>veeeeryyyyy lloooooonnngggg teeeexxxtttt</a>
Expected output:
<a>short text</a>
<a>shrt txt</a>
Or more better is [^<>]{15,100} it replace everything between tags

multi-line xml regex in sublime

I have a large logfile (+100 000 lines) in XML like so:
<container>
<request:getApples xml="...">
...
</request:getApples>
<request:getOranges xml="...">
...
</request:getOranges>
</container>
...
I want to extract the :getXXXX part to
getApples
getOranges
by doing a regex find & replace in Sublime Text 2.
Something like
Find: [^(request:)]*(.*) xml
Replace: $1\n
Any regex masters that can assist?
Correcting mart1n's answer and actually using ST2 and your sample input, I came up with the following:
First, CtrlA to select all. Then, CtrlH,
Search: .*?(get\w+) .*
Replace: $1
Replace All
Then,
Search: ^[^get].*$
Replace: nothing
Replace All
Finally,
Search: ^\n
Replace: nothing
Replace All
And you're left with:
getApples
getOranges
Not familiar with Sublime Text but you can do in two parts:
Find .*?\(get\w+\) .* and replace with \1. Now those get* strings are on separate lines with nothing else. All that remains is to remove the cruft.
So, many ways to do this. Easy one: find ^[^g][^e][^t].*$ and replace with nothing (an empty string).
Now you have your file that contains just the string you want and some empty lines, which (I hope) Sublime can get rid of with some delete-empty-lines function.
You can quickly throw all of the above in a macro and execute at will for any input following the same format ;-)
If you're willing to take the problem out of sublime text, you can use the dotall flag along with lazy matching to extract only the getXXX parts.
Replacing
.*?(get\w*) .*?
with
$1\n
should get you most of the way, only leaving a bit of easily removeable closing tags at the end of the file that I can't figure out at present.
You can check this solution here.
Maybe someone could take this and figure out a way to remove the extra closing tags.
Try this
Find what: :(\w+)>|.\s?
Replace with: $1
And if didn't work as intended, then let me know?