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

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

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

Posted By:      Posted Date: August 28, 2010    Points: 0   Category :.NET Framework
\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!

View Complete Post

More Related Resource Links

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

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

How to extract City State Zip using Regex match

Hi there - I am parsing a file which contains customer address in the following 2 formats:   Format #1 12345 Melrose Place New York NY USA 12987     Format # 2: 12345 Melrose Place New York NY 12987   I need to put the data into Address, City, State and Zip fields. I am able to parse and put the data (specifically line 2) in the fields for format #1 but am having issues doing the same for format # 2 because format # 2 doesn't have USA as a reference point. Below is my code if any expert can help that will be appreciated Dim AddressChunk As String = tokenizer.NextToken() If AddressChunk.Contains("USA") Then _State = AddressChunk.Substring(AddressChunk.IndexOf("USA") - 4, 2).Trim _City = AddressChunk.Substring(0, AddressChunk.IndexOf("USA") - 4).Trim _Zip = Regex.Match(AddressChunk, "\d{5}").Value Else _Zip = Regex.Match(AddressChunk, "\d{5}").Value _State = AddressChunk.Substring(Regex.Match(AddressChunk, "\s[a-zA-Z]{2}\s\d{5}").Value - 5).Trim _City = End If

SQL data type for HL7 message retaining carriage return and new line characters

Hi, What data type should be used for a column storing text as descripted in title? Please advise. I crrently have the message stored as text, but if I copy the message from studio management to a notepad, it will be come one big line of text instead.  

Negate predefined words using Regular Expression Validator

Hi Any one please tell a regular expression which allow all, except some predefined words. For example user should add their imaginary planet names to text field. So if he typed the existing planet names regular field validation don't allow further. i tried [^({Mercury})|({Venus})|({Earth})|({Mars})|({Jupiter})|({Saturn})|({Uranus})|({Neptune})|({Ceres})|({Ploto})|({Haumea})|({Makemake})|({Eris})] but not working. Its not working for any strings. Please tell me the correct way to do this One more thing i want to know is how lengthy expression can be given to the Regular Expression Validator. Thanks Akeeq

Help me modify regex code, only one line.

I have this code Dim parts As New List(Of String)(Regex.Split(RichTextBox2.Text, "~\d")) That splits lines in this format into parts: ~1Hello~2~3Bye~4~5Morning~6 So if I do MsgBox(parts(5)), it will show me "Morning". ------------------------------------------------------------------------ I want to do the exact same thing, but now my my line is arranged like this: Hello, Bye, Morning,   

Paragraph and Line Break Characters

Hello Everyone. While coding my website, I ran into a strange oddity that I can not figure out.  I was working with the MasterPages file and had some fat fingers, thus hitting a few strange keys.  I don't have any idea which ones they were exactly.  After continueing on the coding, I later noticed that my paragraphs were not displaying as they usually do.  Normally, I can have the following code:<p />This is paragraph one. <p />This is paragraph two.  This would show up like a standard set of paragraphs, with a single empty line in between.  After hitting the unknown keys in Visual Studio, the paragraphs no longer work as expected.  I've had to change my HTML to...<p>This is paragraph one.</p> <br /> <p>This is paragraph two.</p> I'm not particularly opposed to either way, however, the problem has arisen that the page viewed over my mobile phone doesn't view the same as over the computer.  There are now several extra lines between paragraphs.   What did I do wrong?  I've recreated the page from scratch and I've looked at all the properties I can find.  Google has been no help at all. Thanks in advance! P.S.  You can see the exact same page displayed Content Text using different MasterPages atHttp://Www.McsoPosseResources.Org/Http://Www.McsoP

regex match body tag - help



I need regex code to get all content between body tag..

I search on all over the internet but those I find - not working!

example code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="http://www.w3.org/1999/xhtml">
   Example paragraph content
   <br />
  <h1>Header 1</h1>


Please help me.

Regex match a number between 100 and 200 and no letters


Hello i`m new in regex and i relly need some help how to fin a solution in this problem

match a number between 100 and 200 inclusive and no letters allowed

Thx in advance hope some one will help me with this

Best regards


The 'REVIEW' start tag on line 117 does not match the end tag of 'REVIEWTYP'. Line 117; position


Using xml file in an application.

received following error,

"The 'REVIEW' start tag on line 117 does not match the end tag of 'REVIEWTYP'. Line 117; position 21."

The above error is not reproducible and when I check the file after error occured, I can see the tags present (both tags correctly).

I tried opening file in different editors, notepad, studio, explorer etc but not found any mismatch. (using Windows XP Japanese for development) . The target machine is XP English.

Can somebody help me in understanding the error and the reasons?

SSIS Error Text was truncated or one or more characters had no match in the target code page


I the same issue or something close.

Except I have one Field (27) that get a trunacation error


Data conversion failed. The data conversion for column "Column 27" returned status value 4 and status text "Text was truncated or one or more characters had no match in the target code page.".

The "output column "Column 27" (91)" failed because truncation occurred, and the truncation row disposition on "output column "Column 27" (91)" specifies failure on truncation. A truncation error occurred on the specified object of the specified component.


Data looks like:Red Text is the field that is throwing the error!





"RUTH           ",

"EDWARDS             ",









"1447203880    ",


Regex with min characters and no spaces


Hi everyone-

How can I make this regex not accept spaces?: [0-9a-zA-Z' ']{3,}

Everything I'm reading says to put a * or a + after the [] , but I get an invalid expression error when I do.  The end result I'm looking for is a string of letters and numbers only -  no spaces inbetween.

regex.match seems to get hanged and also increases the CPU usage to 60-100%

regex.match seems to get hanged and makes the CPU usage to 60-100%. Is there any solution for this problem or any other workaround? please help ....!!!
 Public Sub OUT()
   Dim strPatternString, strRepeaterString As String
   Dim objRegex As Regex
   Dim objRegexMatch As Match

   strPatternString = "^(\\n)*(\s)*(?<OUTPart>((?<OUTGoingIdentifier>OUT)\\n\s*)(((?<OUTList>(?<OutgoingInfo>((?<ConfiguredDelimitersPattern>[/\.\.$/]{1,}))(((?<Type>[a-z][a-z0-9]{2})|(?<Type>[a-z]{3}))){0,1}((?<SerialNumber>[0-9]{5})|(?<SerialNumber>[a-z0-9][0-9]{3,4}))(((?<OwnerCode>[a-z0-9]{2}[a-z]{0,1})|(?<OwnerCode>[a-z0-9]{2}[a-z]{0,1})){0,1}){0,1}((/|(?<ConfiguredDelimitersPattern>[/\.\.$/]{1,}))(?<UnloadingCode>[a-z]{3})){0,1}((/|(?<ConfiguredDelimitersPattern>[/\.\.$/]{1,}))(?<ContentCode>[a-z]{1,2})[ ]*){0,1}){0,}\\n\s*)+)|((?<NilOutGoingDetail>(\.|(?<ConfiguredDelimitersPattern>[/\.\.$/]{1,}))N[\\n]*))))((SI )|($))"
   strRepeaterString = "OUT\n.PMC19415CV/MST/C.PMC16266CV/MST/C.PMC18111CV/MST/C\n.PMC16676CV/MST/C.PMC12800CV/MST/C.PMC19931CV/MST/C\n.PMC20327CV/MST/C.PMC13937CV/MST/C.PMC20041CV/MST/C\n.PMC15891CV/MST/C.PMC20505CV/MST/C.PMC12699123CV/MST/C\n"
   objRegex = New Regex(strPatternString, RegexOptions.IgnoreCase)

Difficult REGEX pattern match [For newbie]


I was hoping someone with far more experience with regular expressions, particularly in .NET, could help me come up with a pattern. I have a program that will be reading in sql files and creating a deployment manifest based on the files. I need to match the file names to first, validate that they match a predetermined pattern. Then, extract certain parts of the file name for metadata in the manifest. The file nameing pattern is like the following:


So, for example, I may have a file named MyProj_sp_GetCustomers_By_ID_2.sql. I need to first do a match on the name to verify that it ends in a number between 1 and 9999. I will then have to assume that the file was named properly (this is a new naming sceme and numbers were not allowed in the proc names previously). the next step will be to extract the Project, ProcName, and Version to properties.

All-in-all this seems relatively simple. However, my sticking point is the proc name. It can be any length and contain 0 or any number of underscores. How do I create a regex that essentially "says" the following:

 - Project name is everything up to the firt underscore.
 - Version is a numeric value between 1 - 9999 that comes after the last underscore and before the file extension.
 - The procedure is everything in-betwe

need a REGEX pattern to match


need help with validating a 9-digit number.
CANNOT BE -----------

4-5 position(s) CANNOT BE 00 --

6-9 position(s) CANNOT BE 00 --

The nine numbers CANNOT BE sequential -- but only the following 4 four below, for the time being --

I had just managed to get the first piece done --

Thanks a TON for the help friends.

Need Regex to eliminate match on certain condition


Apologies for cryptic Title.

I have a simple list of keywords that is used as the expression in a regex:

(Lowes|Home Depot|Starbucks|Wendy|Target|etc. etc.... a couple hundred terms...)

I am searching through html documents so "Target" is a hit if there are any anchor tags with target="_blank".

I need to match any "target" unless the only match for it is "target="

Make sense? Thanks.

Bob - www.crowcoder.com
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