If we have the following lines
<something>A<else>
<something>B<else>
<something>C<else>
Using regular expressions in Notepad++ how to remove all and keeps the letters to be
A
B
C
I've used to replce (.*)(>)(.*) by \3 but didn't worked so anyway what would be the command if i want remove all (things) before (something) and all (things) after.
Thanks
Dear Manal Nor, welcome to Stack Overflow!
I achieved the above result using the following code in Notepad++ 5.6.8:
"FIND WHAT":
<[^>]+>([^<]*)<[^>]+>
"REPLACE WITH":
\1
Let me know if it works!
try search ^.*>(.*)<.*$ and replace \1
I don't have the program here but try something like replacing
.*>(.*)<.*
with
\1
I went with:
(<.*>)(.*)(<.*>)
\2
and that seemed to work for me.
or just
<.*>(.*)<.*>
\1
Related
I have this:
1200
3701
Trying to get this:
100ct1200
100ct3701
But got this:
100ct([0-9])([0-9])([0-9])([0-9])
Because I used regex in find & replace:
Find: ([0-9])([0-9])([0-9])([0-9])
Replace: 100ct([0-9])([0-9])([0-9])([0-9])
Actually I don't know how to express it to just add 100ct infront of the numbers and leave the rest as-it-is. Help? Thanks!
You need to use the following syntax
Find: (([0-9])([0-9])([0-9])([0-9]))
Replace: 100ct\1
Note the parentheses around the whole find expression: \1 refers to their content.
EDIT:
You can also use some shorthands for the Find expression:
Find: (\d{4})
It means "match 4 digits".
Your find and replace commands should be,
Find: ([0-9][0-9][0-9][0-9])
Replace: 100ct$1
$1 or \1 or #1 according to your tool.
Find: ([0-9][0-9][0-9][0-9])
Replace: 100ct$1 or 100ct\1 depending on the language (not sure what syntax Notepad++ uses).
Demo: http://regex101.com/r/cT1mJ8/1
I have 58K files where I need to find this expression
()">A Random sentence.</A></P>
and i need to replace A Random Sentence by nothing.
I was trying on Notepad++ something like
Find What: ()">[[:alnum:][:punct:][:space:]]</A></P>
Replace: <empty>
Not even gettng results from the search...
Waiting for some feedback.
Try to find
(\(\)">).*(<\/A><\/P>)
and replace it with
$1\<empty\>$2
The idea is to save left part and right part, placing essential parts in brackets ().
The ".*" means every character in between.
In replace statement we call $1 and $2 to access saved parts.
You also can try :
(?<=\(\)">)[a-z \.-]+(?=</A></P>)
here [a-z \.-] you put everything what you want to search
Also parenthesis in Notepad++ should be mark with \
This should work for you:
Find: (?<=\(\)">)A Random sentence.(?=<\/A><\/P>)
Replace: <empty>
If A Random sentence. is not the actual sentence you can replace the find with:
(?<=\(\)">).*?(?=<\/A><\/P>)
Sorry for not knowing the basics of regular expressions and asking this, but I couldn't get to it myself.
I need to replace all expressions PlayerTextDrawSetString(SSbank[playerid],strBank)
with PlayerTextDrawSetString(playerid,SSbank[playerid],strBank)
,
PlayerTextDrawSetString(SWant[someid],strWant)
with PlayerTextDrawSetString(someid,SWant[someid],strWant)
etc.
I can find such expressions with PlayerTextDrawSetString+\(+.+\[+.+\], but I can't replace them with that (\1, \2, \3 etc. return empty symbol).
I tried different search strings, but in all cases I get nothing on \1, \2, etc.
Could you please write the correct regex for me?
Thank you in advance for the help.
Try these expressions:
Search:
(PlayerTextDrawSetString\()(\w+\[)(\w+)
Replace:
\1\3,\2\3
The first two examples work.
Search Pattern 1:
SSbank\[([^\]]+)\]
Replacement Pattern 1:
\1,SSbank[\1]
Search Pattern 2:
SWant\[([^\]]+)\]
Replacement Pattern 2:
\1,SWant[\1]
To go all out if you have a lot of these similar patterns you can do this:
Total Replacement Search:
\((\w+)\[([^\]]+)\]
Total Replacement String (yes the first slash is needed... a bug maybe?):
\(\2,\1[\2]
Look behind is apparently broken.
I tried to give Notepad++ a shot with the positive look behind but the replacement fails even though the match happens. Here's the pattern:
(?<=\()(\w+)\[([^\]]+)\]
My attempted replacement (doesn't replace anything in Notepad++ v6.3.2):
\2,\1[\2]
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',
I have a query where I want to replace
avg(j2)
with
avg(case when j2 <> 0 then j2 else 0 end)
The above is a specific example but the pattern is the same with all the replacements. It's always a word followed by a number that needs to be replaced with the case statement that checks if the number is not 0.
I tried the following for find:
avg(\(\w\d\))
and the find works. Now, I want to do a replace so I try:
avg(case when \1 <> 0 then \1 else 0 end)
but it puts literal \1 and not the captured text from the match. I tried \\1 & $1 as well and it takes all of them literally. Can anyone tell me what the right syntax is for using the captured text for replacement? Is this supported?
Thanks,
Ashish
I am not sure if the PL/SQL Developer IDE supports group capture. The recent versions do seem to support regex based find and replace though. Cant find a source to confirm if group capture works.
Why dont you try pasting the code in a something like Notepad++ and try the same regex. It should work. You could paste the result back to your IDE and continue from there...
You can replace it using $ and number like,
$0 or $1 etc. see an example below
find: TABLE (.*\..*) IS
replace: COLUMN $1 IS
http://regexr.com/3gm6c