Replace using Regex - 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

Related

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.

replace text with regular expression keeping structure match on sublime text

i been trying a few options, but i can't figure out.
this is the text i'm looking for:
php[whatever_is_in_between]myfunction
and i want to change it to this
=[whatever_is_in_between]myfunction
where [whatever_is_in_between] = \n or \n\t or \n\t\t or \nbarspace or \nbarespace\t and so on
so i found this regexp match the search text:
php[\n]*[\t]*[ ]*myfunction\(
this is the "replace with" text:
=[\n]*[\t]*[ ]*myfunction\(
but the regexp does not work on the replacement, it replace it as text.
can anybody help me with this?
thanks
I think the problem is that you are not using a capturing group ( ). Among other things, a capturing group allows you to take input from the the read text and then inject it into your replacement text.
I'd use a search pattern like this:
php\[([^\]]*)\]([\w\W]*)
It looks complicated, but I've set up a sample on Regex 101 that you can check out. The replacement text should look something like this:
[\1]\2
Please note that how you insert a capturing group will depend on what programming language you're using. The above should work for php.
I hope that helps,
--Jonathan

Find and replace using regular expressions in Notepad++

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

(Notepad++) Replace with regular expression: FixedText(xxx[yyy],whatever) to FixedText(yyy, xxx[yyy],whatever)

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]