.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

need a REGEX pattern to match

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :Windows Application

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.

View Complete Post

More Related Resource Links

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

does static Regex.Match(string input, string pattern, RegexOptions ops) cache ?


in msdn, it is said that static Regex.Match(string input, string pattern) caches for future uses,

but it doesn't say whether static Regex.Match(string input, string pattern, RegexOptions ops) caches.

Then does it cache? Does it help to promote performance at creation?


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


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

Regex pattern for text extraction within html tag

Hi guys, ive originally posted this question in the "visual basic general" category and was forwarded here.   I am looking for the regex pattern for text extraction within this html tag  <span class="listingTitle">Inner Balance</span> This is the full link if its needed: http://www.yellowpages.ca/search/si/1/Estheticians/Calgary+AB Get I get some assistance please.

What is the Regex pattern of SessionId

Hi asp.net 4.0 I wonder what the Regex pattern for session id is?

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


Pattern not catching a match if numeric preceeds an Alpha [Example included]


When a number preceeds a cell reference in an Excel arithmetic calculation a Regex match will not be found in that instance

If a string = "=IF(H84>H80*0.91,H84,H80*0.91)" <<<<<<  In this case two matches are made for 0.91 and for a 2nd 0.91
                      - vs -                         ____ |

What components of a RegEx Pattern need to be deleted to cancel the appending of Math Operators to t


The following RegEx Pattern ID's Constants in Excel Formulas.  In addition, the Pattern appends the Operator (which actually preceeds the Constants in the Excel Formula) to the Constants and I would like the Operator to disappear as prepended of appended.

Possible candidates for deletion are: >>>>                  [^-+*/^<>=]+    [-+*/^<>]

Dim Pattern As String = "(-?(('[\s\S]*?'!\w+)|(\([\s\S]*?\))|([^-+*/^<>=]+)))([-+*/^<>][<>=]?|$)"

That said, in case I need a revised prepending-pattern in the future, I would like two solutions (Match Patterns) :

1) No Operators appended or Prepended at all (Constants only)


2) Operators (which precede the Constants in Excel Formulas) Prepended to the Constants


Thanks! Dennis

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)

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

Find ISBN 10 or ISBN 13 substring RegEx.Match


Hi, i am trying to find an ISBN substring:

Regex regex = new Regex(@"ISBN(-1(?:(0)|3))?:?\x20+(?(1)(?(2)(?:(?=.{13}$)\d{1,5}([ -])\d{1,7}\3\d{1,6}\3(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\4\d{1,7}\4\d{1,6}\4\d$))|(?(.{13}$)(?:\d{1,5}([ -])\d{1,7}\5\d{1,6}\5(?:\d|x)$)|(?:(?=.{17}$)97(?:8|9)([ -])\d{1,5}\6\d{1,7}\6\d{1,6}\6\d$)))");

Match m = regex.Match("one two ISBN-13: 978-0-470-04673-9 three");

I got the regex from regexlib.com and understand it should match either on a 10 or 13 digit ISBN. Unfortunatly match always returns false.

I would also like it to be able to find the ISBN even if there are no spaces either side, i.e. "one twoISBN-13: 978-0-470-04673-9three" if that is possible.

So far not working, will take another look tomorrow (is 3am now!) but in the meantime if anyone has any pointers would be muchh appreciated.



Need help to match pattern




I would like to split some input strings following a same token that is available in 2 forms, if it's at the beginning of the input string it's

the token but after it's prefixed by a quote. For instance let's take an example with one input string and a token named RFF+ :

input string:


and I would like to split according RFF or 'RFF to get the following result :

splitted[0] = AUM:SMARTMOB
splitted[1] = AUN:CORTASIS RDFC::1.0
splitted[2] = AUO:2002.03.0078



Regex.Match does not return and hangs forever


I have encountered a problem with the Regex.Match() function that it hangs forever. I am unable to figure it out why it hangs.


Regex myRegex = new Regex(@"^\s*(\w*_*\w+_*(\d+)\s*){2,}\.{3}\s*(\w*_*\w+_*(\d+|n|\d+/\d+)\s*){2,}\W*$", RegexOptions.IgnoreCase);

String myPattern = "2_VarA1  3_VarA2   4_VarB1  5_VarB2 6_VarC1  7_VarC2 8_VarD1  9_VarD2";

// The following line hangs forever


I've tried it using Derek Slager's .NET Regular Expression Tester and it also hangs forever.



The problem was initially encountered on .NET 2.0 but I was able to reproduce it in a small program set up to run and compile using .NET 4.0 too.

Help with RegEx Match, matching after the first occurance

I can't seem to get the regex I need for this match. I have an html document that has multiple <DIV id="Emag_Header"> tags in it. It's an html render of a magazine article from a web page. What I need to do it get all html including the first occurance of the div. I then need all html up to the next occurance of the div. I then want to omit the div but get any html after that. All the time omitting the div (after the first one which needs to be in there). I tried a capture/replace method like this:

regex = @"(<DIV[\s?]+Id=""Emag_Header"">.*?</DIV>.*)<DIV[\s?]+Id=""Emag_Header"">.*?</DIV>(.*)";
 content = reg.Replace(content, "$1$2");

 The idea was to grab the first occurance and all html up to the second occurance, then grab all the html after that. Of course it works fine for the first two occurances, but the .* at the end matches everything (as its supposed to), and a 3rd occurance of the div will be in there....

Can anyone help me get this:

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