Regex for two years separated by a forward slash [closed] - c#

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.

Related

Regex with leading zeros [closed]

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.

Find line number of XML string based on XPath [closed]

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;

Find and replace with regular expression C# [closed]

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.

Get words start with # like facebook mentions by regex and javascript [closed]

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.
first of all i know there is many topics talks about this case but not like i want
i want to get the words like Facebook do in mentions names in comments
here is my conditions
1- i want all words start with # char
2- i want all lonely # char
3- i don't want any words that contain '#' like any#hotmail.com
EX: "# this d#y #hmed #nd May# went to play # g#arden"
the result i want is
{"#" , "#hmed" ,"#nd" , "#"}
please notice the second condition i want
thanks
The regex should be /(?:^|\s)(#[^#\s]*)(?=\s|$)/g
[ test: http://ideone.com/1LK80 ]

What data types do the RangeValidator control support? [closed]

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.
explain the rangevalidator control,is it take string also? explain thank you
It supports
Currency
Date
Double
Integer
String
For comparing strings better to use Regularexpressionvalidator instead of Rangevalidator.
In case of type string for the range validator it will only check the character by character, not the length of the string.
Yes, it does support string range validation.
Please look at the documentation before asking question.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.rangevalidator.aspx
MSDN:
The RangeValidator control allows you to check whether a user's entry is between a specified upper and a specified lower boundary. You can check ranges within pairs of numbers, alphabetic characters, and dates. Boundaries are expressed as constants.

Categories

Resources