.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Regex Negative Lookahead

Posted By:      Posted Date: September 03, 2010    Points: 0   Category :.NET Framework
According to documentation from the following websites C# Regex engine should be able to handle negatives lookaheads. Website: http://www.aspnetajaxtutorials.com/2008/04/regular-expression-syntax-use-in-aspnet.html. Here is the documented syntax from the website: (?!...) Matches if ... doesn't match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if it's not followed by 'Asimov'. When I try use this exact example in C# it is not evaluating properly. When I try to use Regex builder Tool (http://renschler.net/RegexBuilder/) it does not evaluate properly either. Could this be a bug in C#?

View Complete Post

More Related Resource Links

Easy image processing(grayscale, sepia, negative, resize, brightness, contrast and opacity)

Howdie y'all,

I see a lot of questions in this forum about resizing images. Recently I created a code sample(with downloadable webapp), right here.

The class (downloaded or created) allows for very fast and easy processing of your images. And a lot of problems over here can be solved by simply using that class. I thought it might help to mention the code sample in this forum as well.



Regex pattern for validating IPv6


Can anyone can make a regular expression pattern for validating IPv6 (not IPv4)?

Ipv6 has many formats and aliases. I tried making the pattern but written in a lot of codes (i'm not sure my code below will be 100% accepting valid formats and 100% declines invalid formats).


Does the use of regions have a negative impact on the application?


Does the use of regions have a negative impact on the execution of the code?  Are there any negative side effects from using these?

Are they completely ignored at runtime?

Regex.replace [h2] to


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:


So that is not what i want.
After the first 1, he should make:


Whats wrong?

regex: How to allow a comma?

Hi,How to allow a comma?"^ \ $? (\ D (1.3),? (\ D (3 },?)* \ d (3) (\. \ D (0.2))? | \ D (1.3) (\. \ d (0.2))? | \. \ d (1.2 }?)$"  This is works, I need character ","Helpthanks

GlobalMemoryStatus returns negative junk value

Hi all,i am retrieving total physical memory using GlobalMemoryStatus() as follows :public struct MemoryStatus{public uint Length; //Length of struct public uint MemoryLoad; //Value from 0-100 represents memory usage public uint TotalPhysical;public uint AvailablePhysical;public uint TotalPageFile;public uint AvailablePageFile;public uint TotalVirtual;public uint AvailableVirtual;}MemoryStatus stat;[DllImport("kernel32.dll")]public static extern void GlobalMemoryStatus(out MemoryStatus stat);GlobalMemoryStatus(out stat);uint totPhy = stat.TotalPhysical;My question is 1) Is the stat.TotalPhysical return the actual physical memory installed int he machine ?2) I am getting neagtive value like -271691776 for the vista mahcine(Os type : 6.0.6001) and Windows Server 2000 . What is the reasonCan someone please help me out.Thanks in advance

multi-line regex in C#

Hi, I am sure this is really simple, but i can't figure it out. I have a string that looks like this: REV=A1 STATUS=Working I would like to grab 'A1' and 'Working', in a single regex, but i cannot seem to handle the linebreak. I have tried putting something together in Rad's Regular expressions designer and this pattern will match it all: REV=(?<Rev>.{2}) STATUS=(?<Status>.+) but i don't know to write a two-lined regex in C#. I have also tried to include the linebreak, with both \n and \r, but none of them worked. So, how is my pattern suppoed to look for this?Nicolai Søndergaard LM Glasfiber A/S

I need a regex for the following sentence

I have a line of text which is as follows  : This should occur before variable1 = 1 variable2 =2 variable3=6 variable4=9   I want a regex which checks if this text (This should occur before ) comes before  the string of the variables (variable1, variable2, variable3, variable4 ) and also  should pass if the placement of the variables can occur anywhere in the sentence.Also the regex should pass only if the variable4 has a value greater than 9.  

Regex for checking number greater than 9

Hi All , I need to write a regex which can check for a number greater than equal to 9 .  

Exclude a word regex

Currently i am using one regex for accepting some records from a file.  That regex is ^[a-zA-Z0-9| ].*$. This regex accepts record starting with alphanumerics or blank space.I want to modify this regex such that, previous conditions should be there and regex should not accept record starting with word 'bbb'. Which regex should be used?

Need RegEx for four decimal place

Hello All, I have total 19 digits in which i have 4 decimal place. What would be the pattern. ThanksBizTalk Beginner

Formating Text using Regex

Hello Everyone,   I have extracted some text from HTML pages & writing it to a Text file. Text is scrambled everywhere in the file after saving.   in the output text there some new line , tabs etc ... is there any way to remove them ? using Regex ?? text i am getting after extraction :- ( checked using Debug ) Pradeep \r\n\t\t\t\t\t\t\t    \r\n\t\t\t\t\t\t      G\r\n                               \r\n                                 \r\n                                \r\n                                State College \r\n                                 \r\n 

Split string using Regex with escape sequences

What is the regex to split a string using the delimiter ';', but not split on '\;' ? Backslash would be my escape character in my split string, so finding '\;' would not split, but '\\;' would split. For example I want a regex that would split the following:     "aaa;bb;cccc\;dd\;eee\\;ff\\;ggg\\\;hhh" into the following string array:     aaa     bb     ccc\;dd\;eee\\     ff\\     ggg\\\;hhh   Thanks!   -Sylvain

Best regex for email body on contact form?

I'm not sure the best way to do a regex for the body section of an email contact form.  I want to use the regex to prevent more than 150 characters from being entered.  I assume this is sufficient, I may need more.  I also want it to help guard against sql injection attacks. The more I think about it the more characters I can think of that should be allowed.  I want to allow punctuation since it's for an email and people should be using full sentences.  These are some other things that make sense to allow: " , ', : , ; , $ , . , ! , ? , - , _ , @ , & , ( , ). They cover situations when someone may put an email address or phone number in the body section for the email.  I also want to allow letters and numbers.    I'm not sure if it's best to allow the characters I mentioned or not allow characters that pose a potential threat.  I think allowing the ones I want is the best way, but I'm not sure.  Can someone please give an example and/or suggestions?  Are there other characters that should be allowed?  I don't have much yet: "^(?i)[a-z0-9\s]{1,150}$"

REGEX does not match when line ends with the characters.. also, how to negate words that contain the

\S*(ai|ie)\S*   seems to match all words with characters ai and ie in them.  However it does not match if the line ends with them, how can fix that?Also, how can I match all words that DO NOT contain those characters.. I've tried ?! and [^ to no avail.Thanks in advance for any help or information!

How to find misspelled words with regex

Hi all I need a RegEx that will find a specific word within a long string. The issue is that this word may be misspelled and I need to find it even so. I would like to accept a certain percentage of wrong-ness when looking for the word. Ex. The complete string: Hello, this is my comp/et string to look at The word to search for: complete Let's say that I which to accept a maximum of two wrong letters in the above string, then the RegEx should match the word complete. However, if I only accept 1 wrong letter it shouldn't find it. Ideally the RegEx would also be able to handle whitespaces, and missing letters. Ex: The complete string: Hello, this is my com plee string to look at The word to search for: complete This should match the word as well, even though there is a whitespace between 'm' and 'p' and the letter 'l' is missing. Is this possible at all with RegEx or should I be looking at an alternative way to solve it? Thanks, Tommy

RegEx, XSD and Dataset not working together?

i have a XSD file that includes that includes the simple types     <xs:simpleType name="PhoneNo">         <xs:restriction base="xs:string">             <xs:pattern value="0(1|2|3|7)\d+" />             <xs:maxLength value="11" />             <xs:minLength value="10" />         </xs:restriction>     </xs:simpleType>     <xs:simpleType name="Email">         <xs:restriction base="xs:string">             <xs:pattern value=".+@.+\.\w+" />         </xs:restriction>     </xs:simpleType> and the element      <xs:element name="Input" msdata:IsDataSet="true" msdata:Locale="en-GB">         <xs:complexType>             <xs:choice minOccurs="1" maxOccur
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend