.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

Find ISBN 10 or ISBN 13 substring RegEx.Match

Posted By:      Posted Date: April 10, 2011    Points: 0   Category :WPF

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.



View Complete Post

More Related Resource Links

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

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


Regex to find nested list items

Hi everyone,

I am trying to write a regex parser that will extract links from some html that is generated within our services. Now, extracting items in html I am able to do, but I have n idea how to parse the links from the following, and keep the structure, e.g with the following menu

<ul id="menu">

What I have tried is

<ul id=\"menu\"[^>]*>(.*)</ul>

Now, this does get me the whole menu, but then If I do:


I can get the menu items, BUT, I lose the structure.

So I thought I would be able to extract the LI that contain the UL inside it, but the problem is that using the regex above to extract that LI, I retrieve the following:


Can anyone suggest a way that I can use regex to retrieve this keeping the same structure? or another way of processing these menus and being able to record the structure?



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

Using RegEx, how to find substrings enclosed by a special character


Let’s say, special character is: $

Input string: This $abc$ and $def123$ is a test

Desired output:




I tried: @“\$.*?\$"


Got the output as:



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.

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?


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:

find a Control inside a GridView using jQuery


I have databound GridView in my page and I have a hidden DIV in all rows. Each row contains a Button that I want it to make the DIV visible for me! how can I use that with jQuery?!

here is the code page: 

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" 
                                EnableModelValidation="True" GridLines="None" ShowHeader="False" Width="100%">

The number of members in the conceptual type ... does not match with the number of members on the ob



I've added a scalar property to an entity and now ASP.NET Dynamic Data scaffolding throws this error:

The number of members in the conceptual type 'TrainingModel.Users' does not match with the number of members on the object side type 'TrainingModel.Users'. Make sure the number of members are the same.

This happens at the following line in global.asax:
model.RegisterContext(typeof(TrainingModel.TrainingEntities), new ContextConfiguration() { ScaffoldAllTables = true });

Please help!

Is there any way to find out the reason for session expiry?


Dear All,

is there any way to find out the reason for session expiry?



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