Replace a text with regular expression in notepad++ - regex

I want to replace all the url's which are starting with something like www.sitename.com/xxx/xxx.html and the last part of the string is different on each url. Is there any formula in notepad++ which replace the whole string with "#" or any custom character ?

Bring on the Find and Replace dialog, select Replace (Ctrl+H)
Search mode: Regular expression
Find what: www\.sitename\.com/\w+/\w+\.html
Replace with: # (or anything you wish)
This will replace URLs of the type you've provided in question (www.sitename.com/xxx/xxx.html)

Press Ctrl+H to bring up the replace window. Enter this in the Find what: section:
www\.sitename\.com(/\w+)*\.?\w*
and anything you want (#) in the Replace with:. Make sure that Search Mode is on Regulare Expression and the hit the Find next, Replace or Replace All
This will replace all the URLs beginning with www.sitename.com and ending with and extension (.html, .jpg, ...)

Related

notepad++ How to remove multi symbol comma,dot,Exclamation mark

Example
Email me, new! responses ...to ?my posts
Email me new responses to my posts
I search multi time on google . I can replace it one by one but i want a formular remove all symbol one time.
I'm try search and replace with (.|,|?|!|...|) but it's doesn't work.
You have to escape specials characters and select the option "regular expression" in the replace window. This is your regex.
\.|\?|!|\,
If you want to remove all pnctuation marks, use unicode property \p{Punct}:
Ctrl+H
Find what: \p{Punct}+
Replace with: LEAVE EMPTY
check Wrap around
check Regular expression
Replace all

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.

Notepad++ replace text with RegEx search result

I would like replace a standard string in a file, with another that is a result of a regular expression. The standard text looks like:
<xsl:variable name="ServiceCode" select="###"/>
I would like to replace ### with a servicecode, that I can find later in the same file, from this URL:
<a href="/Services/xyz" target="_self">
The regular expression (?<=\/Services\/)(.*)(?=\" )
returns the required service code "xyz".
So, I opened Notepad++, added "###" to the "Find what" and this RegEx to the "Replace with" section, and expected that the ### text will be replaced by xyz.
But I got this result:
<xsl:variable name="ServiceCode" select="?<=/Services/.*?=" "/>
I am new to RegEx, do I need to use different syntax in the replace section than I use to find a string? Can someone give me a hint how to achieve the required result? The goal is to standardize tons of files with similar structure as now all servicecodes are hardcoded in several places in the file. Thanks.
You could use a lookahead for capturing the part ahead.
Search for: (?s)###(?=.*/Services/([^"]+)") and replace with: $1
(?s) makes the dot also match newlines (there is also a checkbox available in np++)
[^"] matches a character that is not "
The replacement $1 corresponds to capture of first parenthesized subpattern.
I am no expert at RegEx but I think I may be able to help. It looks like you might be going at this the wrong way. The regex search that you are using would normally work like this:
The parenthesis () in RegEx allow you to select part of your search and use that in the replace section.
You place (?<=\/Services\/)(.*)(?=\" ) into the "Find what" section in Notepad++.
Then in the "Replace with" section you could use \1 or \2 or \3 to replace the contents of your search with what was found in the (?<=\/Services\/) or (.*) or (?=\" ) searches respectively.
Depending on the structure of your files, you would need to use a RegEx search that selects both lines of code (and the specific parts you need), then use a combination of \1\2\3 etc. to replace everything exactly how it was, except for the ### which you could replace with the \number associated with xyz.
See http://docs.notepad-plus-plus.org/index.php/Regular_Expressions for more info.

Regexp different behaviours in notepad++

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

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