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
Related
Given this example text:
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ABB</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="FM"/>
...lines...
...........
</abr:rules>
<abr:rules>
<abr:ruleTypeDefinition>
<abr:code>ADE</abr:code>
<abr:ownership>
<abr:owner organization="NT" application="DCS" subapplication="CM"/>
...lines...
...........
</abr:rules> (end of group)
I would like to find and remove all that goes from <abr:rules> to </abr:rules> with the condition that subapplication IS NOT "CM". Organization and application are the same, <abr:code> it's any string.
What I tried so far is
<abr:rules>\n<abr:ruleTypeDefinition>\n<abr:code>[a-zA-Z0-9]{3,}<\/abr:code>\n<abr:ownership>\n<.*"(FM|PSD|SSC)"\/>\n(?s).*?\n<\/abr:rules>\n
which works but only because I know the other subapplication names.
Is there any way to do it with Regex only ?
Try the following find and replace:
Find:
<abr:rules>((?!subapplication=).)*subapplication="(?!CM")[^"]+"((?!</abr:rules>).)*</abr:rules>
Replace:
(empty string)
Demo
Note: The above pattern will only work if you enable dot in Notepad++ to match newlines. If you don't want to do that, then you may use [\S\s] instead of dot.
You should not use regex for xml, you can read why here:
https://stackoverflow.com/a/1732454/3763374
Instead you can use some parser like Xpath
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.
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]
Need some help in Notepad++
Example how it looks at the moment
http://www.test.com/doc/rat.rar">rat.rar
http://www.test.com/down/ung.rar">ung.rar
http://www.test.com/read/add.rar">add.rar
......
How I want it (just remove after ">....rar)
http://www.test.com/doc/rat.rar
http://www.test.com/down/ung.rar
http://www.test.com/read/add.rar
Its a list about 1000 lines. So help would be nice
Use the following expression:
">[^.]+\.rar
Explanation:
"> # literal `"` followed by literal `>`
[^.]+ # any character that is not a `.`, repeated at least once
\. # literal `.` character
rar # literal string `rar`
Note: a couple of other answers pointed out that just ">.* will work. This is true, because Notepad++ doesn't appear to support multi-line regular expressions, even with [\s\S]+. Either way will work so it's personal preference. The regex I gave in this answer is very verbose and would reduce the likelihood of false positives. ">.*, on the other hand, is shorter.
In regexp mode , replace pattern ">.* with empty string.
">.*
Search for this and replace with nothing.
Your search string should be ">.+\.rar, and you can just blank out the replace box. This should do the job.
Also, check that you've got regex selected at the bottom of the replace box ;)
If you put this in find ".* and nothing in replace, that should do what you're looking for.
Remember to check that you've got regex selected at the bottom of the replace box.
Flick the "regular expression" radio button and then use this for your FIND:
">[a-z]+\.[a-z]+
Then just put empty space for your REPLACE and replace all.
Use -
Find What : (.*)">(.*)
Replace With : \1
And check Regular expression option at the bottom of the dialog.
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