I'm having a little trouble with using regex in linq. I want to be able to perform a search on values in my database. The goal is to insert a value into the regex and then use that to search a column in a table in my database for that term. I want it to work so that it gets all exact matches and also returns matches in which the search term is a substring of the term in the column.
I was trying to follow this tutorial on msdn, but it doesn't quite fit perfectly with my problem:
I need a regex or any other solution to replace an id in the middle of a url (not in querystring). url example - http://localhost:1876/category/6?sortBy=asc&orderBy=Popular
replace - category/6 with category/anotherID - routing used - routes.MapRoute( "categories", "category/{categoryID}/{categoryName}", new { controller = "Search", action = "SearchResults", categoryID = "", categoryName = "" } );
I need regex in c sharp to display SSN in the format of xxx-xx-6789. i.e 123456789 should be displayed as xxx-xx-6789 in a textfield. The code I am using write now is
i m using a regex to not allow certain characters, the below code works fine for certain html tags but not for all for i dont want the user to enter html tags for eg if i enter <nitin/> it allows but i dont want this to happen for other html tags it does not allow
!@#$%^&*()+=[]\';,/{}|":<>? or !@#$%^&*()+=[]\';,/{}|":<>/>?
with a regex that would replace the following. The only thing that would remain the same is the div tags, the id's and classes could change and so could the content.
<div id="nav" class="whatever">Content is whatever</div>
The code works, but I need to include some exceptions to the replace - e.g. I will not replace anything i an img-, li- and a-tag (including link-text and attributes like href and title) but still allow replacements in p-, td- and div-tags.
How do I solve the problem below? I'm creating a simple content management system, where there is a HTML template with specific markup that denotes where content should be:
Separate from this, there is content in a database field that looks a little like this:
<!-- #BeginEditable "Body1" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable "Extra" -->This is more test text<!-- #EndEditable -->
As you can guess I need to merge the two, that is, replacing
<!-- #Editable "Body1" -->
with: This is Test Text. I've begun the code here. But I'm having problems using the Regex Replace function that should be located at the very bottom of that For/Each.
//Html Template string html = "<html><head></head><body><!-- #Editable "Body1" --><p>etc etc</p><!-- #Editable "Extra" --></body></html>"; //Regions that need to be put in the Html Template string regions = "<!-- #BeginEditable "Body1" -->This is Test Text<!-- #EndEditable --><!-- #BeginEditable "Extra" -->This is more test #EndEditable -->"; //Create a Regex to only extract what's between the 'Body' tag Regex oRegex = new Regex("<body.*?>(.*?)</body>", RegexOptions.Multiline); //Get only the 'Body' of the html template string body = oRegex.Match(html).Groups[1].Value.ToString(); // Regex to find sections inside the 'Body' that need replacing with what's in the string 'regions' Regex oRegex1 = new Regex("<!-- #Editable "(.*?)"[^>]*>",RegexOptions.Multiline); MatchCollection matches = oRegex1.Matches(body); // Locate section titles i.e. Body1, Extra foreach (Match match in matches) { string title = oRegex1.Match(match.ToString()).Groups[1].ToString(); Regex oRegex2 = new Regex("<!-- #BeginEditable "" + title + ""[^>]*>(.*?)<!-- #EndEditable [^>]*>", RegexOptions.Multiline); // // // Replace the 'Body' sections with whats in the 'regions' string cross referencing the titles i.e. Body1, Extra // // // }
I need to validate if a the ID number that the user typed in my site is a valid ID.
How do I check it?
Do I need to use RegularExpressionValidator?
More over, I also need to validate the credit card number, I found a few RegularExpressions for that in the net but each one is different from the other and I am not sure which one to use.. Does anyone know od a working expression that will suit all credit cards?
1) Should be 6-15 characters in length 2) Should have atleast one lowercase character 3) Should have atleast one uppercase character 4) Should have atleast one number 5) Should have atleast one special character 6) Should not have spaces
Can anyone suggest me a RegEx for this requirement?
I would like to be able to type in a URL like [URL] arrive at a Details Page which parsed the "M" and the "123" from the query string and used them as params to query a Table in my Database. I've been reading my @$$ off and I can't find anything close :>
I want to validate complete Email address. I am not asking to match using pericular string. but suppose someone enter email id a@bnm.com then first the bnm should be validated and if such domain found then also it should check for such a@bnm.com is available or invalid.???
I have a php function, preg match which i need to convert into c#..It has a regular expression "/\s+/"....
Its supposed to match the whole string including newline..and in PHP i am getting the whole string...I want to get the result of the whole string match in C#...i have used Regex.match method...But it returns me a blank array..Suppose the string = "title"....Why am i not getting the correct match..?
I have a Expression ($ASMLNA$ * $TSM$ * 8 * ($GrossDownTarget$ * $005930K$)+15)Now I am trying to get all the variables which is between $ $. Example $ASMLNA$ so for me it should give ASMLNA.I have tried using RegEx and this is what I have been able to do till now
Regex r = new Regex(@"[^$]"); string Contents = txtRegEx.Text.Trim(); MatchCollection ImageCollection = r.Matches(Contents);
string str = "LDAP://company.com/OU=MyOU1 Control,DC=MyCompany,DC=com"; Regex regex = new Regex("OU=\w+"); var result = regex.Matches(str); var strList = new List<string>(); foreach (var item in result) { strList.Add(item.ToString().Remove(0,3)); } Console.WriteLine(string.Join("/",strList));
the result i am getting is "MyOU1" instead of getting "MyOU1 Control"
I want a text box which will accept CSV values and the values can be any time of a day,i.e.,in one text box I can enter multiple clock times,separated by comma.Hour,Minutes will be separated by :.Second no required
If a.m. or p.m. can be associated it would be great[0-12 basis], otherwise 0-24 basis will be fine.
I'm looking for a regex that will allow Alpha Numeric and most all special characters except white space. It should be usable in c#. It would be nice if .net supported posix style but I can't seem to get it to work.
I am trying create a Regex-based replacement for an article to automatically convert embedded references (many of them) in posts into the appropriate link and title format.
For example, given this:
I have already blogged about this topic ((MY TOPIC ID: "2324" "a number of times")) before. And I have also covered ((MY TOPIC ID: "777" "similar topics")) in the past.
... I want to get this:
I have already blogged about this topic <a href='/post/2324'>a number of times</a> before. And I have also covered <a href='/post/777'>similar topics</a> in the past.
I currently have this:
/* Does not work */ public static string ReplaceArticleTextWithProductLinks(string input) { string pattern = "\(\(MY TOPIC ID: \".*?\" \".*?\"\)\)"; string replacement = "<a href='/post/$1'>$2</a>"; return Regex.Replace(input, pattern, replacement); }
But it seems to return lines that contain <a href='/post/'></a> without appending matches instead of $1 and $2.
Question: What is the easiest way to do convert the string #1 above to string #2 above?