It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need to find the mentioned lambda statement and remove it from my code. My project is so big, and I noticed in the find and replace box of Visual Studio, there is an argument that can use regular expressions to find and replace codes. Is there a regular expression that can find this statement completely (contains line break and white space also)?
() =>
{
CallMethod()
},
I'm afraid that VS IDE is using the regular expressions in single line mode (which is actually strange considering that it offers \n in the suggestion menu). I think you will be a lot better creating a new project, which will load the file, read all text from it, and replace whatever regex you specify, and then save the file back.
Basically the regex you need is this:
(\(\ *\)\ *=\>[\r\n\s\{\}]*CallMethod\ *\(\ *\)[\r\n\s\{\}]*,)
In C# code, you can do it like this:
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(#"(\(\ *\)\ *=\>[\r\n\s\{\}]*CallMethod\ *\(\ *\)[\r\n\s\{\}]*,)", System.Text.RegularExpressions.RegexOptions.Multiline);
regex.Replace(document, string.Empty);
Hope this will be of help to you.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I need to match a filenames in the filelist with database rows by Regex.
File names are numbers with leading zeros
Database values are numbers without leading zeros
Sample file list:
0001.jpg
0002.bmp
...
0012.bmp
0013.bmp
0014.jpg
...
1012.jpg
...
1015.jpg
...
I use C#. And I need to match each file name with each row in the database.
You can use this regex
^0+\d+[.](jpg|bmp|jpeg|exe)
OR
^0+\d+[.]\S+
I'm somewhat reluctant to answer, but in order to match those file names (which is what I presume you are trying to do) you should try: \d{4}\.(jpg|bmp)
EDIT:
Since you are so liberal with your -1's..
Regex isn't really the correct technology to use to solve your coding problem, regex is used to find a string that matches a pattern.
The problem you appear to describe is that you have a poorly typed file system with unnecessarily added 0's and want to convert (for example) a 4 to 0004 and not care about what file extension you have.
The "best solution" to your problem is to fix the numbering system of your files or simply to add the leading 0's in c#, not to use a technology that is designed to do something completely different.
Enjoy your -6.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am new to learning Regex and I am struggling with this basic issue. I want to make sure a string is in a format like: 2000/2001 or 2010/2011.
I tried something like: ^[2000-2900]./.[2000-2900]$ but I know this is wrong!
This would be the very basic:
^\d{4}\/\d{4}$
From the beginning of the string, check if it has 4 digits followed by a "/" (escaped with "\") and another 4 digits to the end of the string.
If you searching for where the entire string must match then:
^\d{4}/\d{4}$
If you are searching for a sub string of a larger string then:
\d{4}/\d{4}
And if you using in C# then remember to wrap it up in a verbatim string like so:
#"^\d{4}/\d{4}$"
#"\d{4}/\d{4}"
I noticed that others are escaping the forward slash but I don't think is necessary but doesn't do any harm if you do.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I'm trying to find the line in a multi-line string, containing XML, that a given Xpath points to.
In other words, I have a string containing XML. I have a given Xpath, that I want to use to find the exact line line number of the string.
What's the best way to do this?
You might consider using a an XmlTextReader instead. That has LineNumber and LinePosition properties.
The XmlTextReader does have some limited "read until you reach such-and-such a node" properties, but they aren't as sophisticated as those of XPath. Depending on how complex the XPath is, this might or might not work.
I did find a link on the subject here.
You can load the XML from the string into an actual XML class.
XDocument x = XDocument.Parse(yourStringContainingXML);
string contentOfNode = x.Descendants(XName.Get("NameOfTheNode")).First().Value;
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
When I use the code below, it compiles but the rest of the code doesn't seem to work. When I take out the Substring part of it, it does.
-Steps
String theDate, theWeekDay;
if (ToTime(Time[0]) == ToTime(0, 0, 0))
{
theDate=ToDay(Time[0]).ToString().Substring(0,3);
theWeekDay=Time[0].DayOfWeek.ToString().Substring(4,8);
DrawTextFixed("day",theWeekDay, TextPosition.BottomRight);
DrawText("day"+Convert.ToString(ToDay(Time[0])),
theWeekDay+" "+theDate,0, Low[0]-TickSize*20, Color.Blue);
}
You haven't given enough information to solve your problem, but if you're just trying to get the day of the week name in the abbreviated format, use this instead:
theWeekDay = Time[0].ToString("ddd");
You're going to have to provide more than just this snippet of code. What is the Time object you're accessing via an indexer? Have you debugged this to see if Time[0] actually has a value? My guess here would be that Time[0] doesn't return a value that DayOfWeek can work with hence Substring(0,3) is being running against either an empty string or a null value
Unless you have omitted part of the code, your assignment does not take place within a class definition or a method.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to eval() and run this javascript code from my C# program, but it won't even debug.
How can I do this?
string jsFunc = "eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('8 4=\'6/13!)!6/12))6/19))))2!,!18*!16!15*!,!:14*-!17:9*!,!26***<\';8 5=\"\";20(3=0;3<4.24;3++){10(4.7(3)==25){5+=\'\\&\'}11 10(4.7(3)==23){5+=\'\\!\'}11{5+=21.22(4.7(3)-1)}};5;',10,27,'|||i|s|m|Nbui|charCodeAt|var||if|else|bct|spvoe|521|8477|_|73|2689|njo|for|String|fromCharCode||l{�ength|28|4451'.split('|')))";
JSEval.JSEval eval = new JSEval.JSEval();
string expression, result;
Console.Write("Выражение: ");
expression = jsFunc;
try
{
result = eval.Eval(expression).ToString();
}
catch
{
result = "!!!";
}
One potential problem, if I am permitted to hazard a guess based on the slim details available, is the odd character sequence found in the string:
...||l{�ength|28|4451'.split('|')))";
Perhaps you should remove the {� and re-run the code.
To elaborate on other meanings of the phrase "code don't debug":
Ensure the project is configured to build in Debug mode.
If your expectation is that you can step through the JavaScript, this will not be possible. You should instead debug the JavaScript using something like Firebug.
If you cannot mentally debug the JavaScript, because it has been minified, you should look at a tool to unpack the JavaScript into something more human readable.