C# - How To Regex For Extenionless URL

Feb 19, 2010

In my asp.net application i have url [URL] to match it i have regex

"~/(.+)" which works perfectly fine. But if i navigate to www.site.com/login.aspx again regex matches with this expression "/(.+)".

In Simple words i want a regex which only match the extenionless url. IF extension is present in the url then do not match it

<RewriterRule>
<LookFor>~/(.+)/(.+)/(.+)/</LookFor>
<SendTo>~/Shop/Item.aspx?cn=&1&it=$2&ft=$3</SendTo>
</RewriterRule>

View 3 Replies


Similar Messages:

Using RegEx With LINQ - Insert A Value Into The Regex?

Feb 19, 2010

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:

[URL]

Code:

[code]....

View 11 Replies

C# - How To Replace Url Value With Regex

Dec 8, 2010

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 = "" }
);

View 1 Replies

Regex.replace [h2] To <h2>?

Aug 25, 2010

I try to replace [h2] to <h2> I use this coding:

string o = "<h2>test</h2>";
o = Regex.Replace(o, "[h2]", "<h2>");
o = Regex.Replace(o, "[/h2]", "</h2>");

But the result after the first regex is:

[<h2><h2>]test[/<h2><h2>]

So that is not what i want.

After the first 1, he should make:

<h2>test[/h2]

Whats wrong?

View 3 Replies

C# - Format Ssn Using Regex

Mar 10, 2011

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

string SSN = "123456789";
Regex ssnRegex = new Regex("(?:[0-9]{3})(?:[0-9]{2})(?:[0-9]{4})");
string formattedSSN = ssnRegex.Replace(SSN, "XXX-XX-${last}");

What is correct Reg Expression to mask ssn xxx-xx-6789 ?

View 1 Replies

Two Regex Expressions In One?

Jul 28, 2010

i have the code:

Regex r = new Regex("<tag>([^<]*)</tag>");

but i want to add another set of tags to search between:

Regex r = new Regex("<tag>([^<]*)</tag>|<asd as="b">([^<]*)<asd as=j>");

this does not work.

View 1 Replies

Modifying Existing Regex?

Jan 19, 2010

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
!@#$%^&*()+=[]\';,/{}|":<>/>?

View 1 Replies

Regex For Integer Range

Jul 26, 2010

how i can implemnt a regex that cover integer range? means from 0 to 2147483647

View 9 Replies

Regex To Replace Specific Div?

Feb 8, 2010

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>

View 4 Replies

C# - Regex Replace - But With A Few Exceptions?

Mar 11, 2010

string lNewHTML = Regex.Replace(lOldHTML, "(word1|word2|word3)", "<a href="page.aspx#$1">$1</a>", RegexOptions.IgnoreCase);

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.

View 2 Replies

Using RegEx Replace Function In C# ASP?

Feb 18, 2010

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:

<html><head></head><body><!-- #Editable "Body1" --><p>etc etc</p><!-- #Editable "Extra" --></body></html>

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
//
//
//
}

View 5 Replies

C# - Regex To Get Page Number From The Url?

Jul 4, 2010

I am currently using this regex to get the page number from the url:

@"/(d+)$";

Which worked fine for urls like:

/some_category/2
/some_category2/323

My urls now have some additional querystring values (optionally), so the current regex is not working for these cases.

So now I need a regex to support:

/some_category/2
/some_category2/323
/some_category2/323?a=1&b=2
/some_category2/323?&c=123&a=1&b=2

I am using a route with wildcards so I can use the built in asp.net mvc for this.

View 3 Replies

Regex - How To Validate ID Number

Sep 7, 2010

I am new at this so be easy on me... :)

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?

View 2 Replies

RegEx For Strong Password?

Mar 6, 2010

I have the following password requirements:

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?

View 4 Replies

MVC :: Routing - How To Get URL Parameters With Regex

May 27, 2010

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 :>

View 3 Replies

Regex To Extract Numbers?

Jul 27, 2010

i'm looking for a regex that does the ffg:

string1 = Test1234

string2 = Test9999

i want the regex to return 1234 and 9999 if the string starts with Test.

View 3 Replies

C# - Replace Dot(.) With Comma(,) Using RegEx?

Aug 4, 2010

I am working on ASP.NET (C#) application. I want to change number decimal figure with comma(,) where i have dot(.) using regular expression.

For example:

Price= 100,00.56

As this international rule of representing numeric values but I Sweden they have different ways for numbers Like

Price= 100.00,56

So i want to change dot(.) into comma(,) and comma(,) into dot(.) using RegEx.

View 7 Replies

C# - Email Validate ( Not Only Regex)?

Jan 9, 2011

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.???

View 2 Replies

Regex That Matches Newline?

Mar 29, 2010

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..?

View 4 Replies

C# - A RegEx For Expresions Starting With $?

Jun 4, 2010

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);

[code]...

View 2 Replies

C# - String Manipulation In Regex?

Apr 4, 2011

i have a problem in string manipulation

here is the code

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"

View 2 Replies

Web Forms :: RegEx For Csv Time Value?

Sep 7, 2010

My requirement is as follows:

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.

Accepted Inputs:1:00,12:45,23:59,11:34

View 7 Replies

Regex To Disallow Whitespace?

Feb 8, 2011

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.

View 1 Replies

Regex To Allow Space If Followed By Character?

Feb 2, 2011

I have an asp.net regularexpressionvalidator that I need to match on a textbox. If there is any text, logically the rules are as follows:

The text must be at least three characters, after any trimming to remove spaces.
Characters allowed are a-zA-Z0-9-' /&.

I'm having major pain trying to construct an expression that will allow a space as the thrid character only if there is a fourth non-space character.

My last attempt was:

^[a-zA-Z0-9-'/\&.](([a-zA-Z0-9-'/\&.][a-zA-Z0-9-' /\&.])|([a-zA-Z0-9-' /\&.][a-zA-Z0-9-'/\&.]))[a-zA-Z0-9-' /\&.]{0,}$

but that does not match on 'a a'.

View 2 Replies

Multiple Regex Replacements In C#?

Nov 10, 2010

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?

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved