I want to find and convert statements having arguements in some files.
Search statements are like:
db.AddInParameter(command, "#id", DbType.Int32, entity.Id);
Result statement is like:
command.Parameters.AddWithValue("#id", entity.Id);
I am using Notepad++ and trying regular expressions to create search string. I tried
db.AddInParameter*\"#+[a-z]\"*
db.AddInParameter*"#+[a-z]"*
But can not create the right search string.
Please suggest the correct the search and replace string.
Only change needed for me is adding start and end brackets
So, my replace string is:
\1.Parameters.AddWithValue\(\2, \3\);
Search: db.AddInParameter\((.*?), ("#[a-z]+"), .*?, (.*)\);
Replace: \1.Parameters.AddWithValue(\2, \3);
Related
I have string like this:
&breakUp=Mumbai;city,Puma;brand&
where Mumbai;city and Puma;brand are filters(let say) separated by comma(,). I have to add more filters like Delhi;State.
I am using following regular expression to find the above string:
&breakUp=.([\w;,]*).&
and following regular expression to replace it:
&breakUp=$1,Delhi;State&
It is finding the string correctly but while replacing it is removing the first and last character and giving the following result:
&breakUp=umbai;city,Puma;bran,Delhi;State&
How to resolve this?
Also, If I have no filters I don't want that first comma. Like
&breakUp=&
should become
&breakUp=Delhi;State&
How to do it?
My guess is that your expression is just fine, there are two extra . in there, that we would remove those:
&breakUp=([\w;,]*)&
In this demo, the expression is explained, if you might be interested.
To bypass &breakUp=&, we can likely apply this expression:
&breakUp=([^&]+)&
Demo
Your problem seems to be the leading and trailing period, they are matched to any character.
Try using this regex:
&breakUp=([\w;,]*)&
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.
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.
I have the following:
<d:RowKey>XXXX004K<
replace with
<d:RowKey>050505004K<
and
RowKey='XXXX004K'
replace with
RowKey='0505050004K'
Can someone help me with the regular expression syntax for these. The value of "X" in the above can be any number.
Sorry but I have never used regex before. I just need some way to do this inside notepad++ where it gives me an option of regex for a search string.
Tried with a simple string
string pattern = #"\d{4}004K";
string search = "<d:RowKey>8989004K<";
var result = Regex.Replace(search, pattern, "050505004K");
Try
Find What: ([>'])[0-9][0-9][0-9][0-9]
Replace With : \1050505
Assuming 05050504K< there is a typo in here
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