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


Post New Web Links

Help with RegEx Match, matching after the first occurance

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :WPF
 
Hello,
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:


                                     
                                            
                                        

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

  

Hi,

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"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>
  </title>
 </head>
 <body>
  <p>
   Example paragraph content
  </p>
  <p>
   &nbsp;
  </p>
  <p>
   <br />
   &nbsp;
  </p>
  <h1>Header 1</h1>
 </body>
</html>

 

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.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()
  Try
   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)
   Console.WriteLine(&quo

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:

<Project>_<ProcName>_<Version>.sql

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 -----------
000000000
111111111
222222222
333333333
444444444
555555555
666666666
777777777
888888888
999999999

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

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

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


I had just managed to get the first piece done --
"^(?:(?!0+|1+|2+|3+|4+))\d{9}$"

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

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

Console.WriteLine(m.Value);
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.

Regards,

Chris

How do I prevent the sentence-matching regex ([^.?!]+[.?!]) from matching .?! followed by quotes?

  

Hello All,

([^.?!]+[.?!])

Is there a way of preventing this from matching  .?! that are inside of (followed by) quotations?

For example:

He tossed back his veil, and Gork looked into the features he had seen depicted on the silver coin. "Aye, dog!" The voice was like the hiss of a giant snake.

matches as this (each match on a line of its own):

He tossed back his veil, and Gork looked into the features he had seen depicted on the silver coin.
"Aye, dog!
" The voice was like the hiss of a giant snake.

I'd like it to match as:

He tossed back his veil, and Gork looked into the features he had seen depicted on the silver coin.
"Aye, dog!" The voice was like the hiss of a giant snake.

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
myRegex.Match(myPattern)

 

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

http://derekslager.com/blog/posts/2007/09/a-better-dotnet-regular-expression-tester.ashx

 

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?

 


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

  

 Hello,

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


Is this load full or matching one only... coz of need to know performance

  

Hi..

This my Two Table i have one doubt...

For my first table i have select Top 2 from Employee_info 

and second table itz just selct * from MDEp..

What my doubt is on loading the above report?

Is this load all the record from MDep or just matching one based on Employee_info..?


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

(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,6})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4})
|
(([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3})
|
(([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2})
|
(([0-9a-fA-F]{1,4}:){1,6}(:[0-9a-fA-F]{1,4}){1,1})
|
((([0-9a-fA-F]{1,4}:){1,7}|:):)
|
(:(:[0-9a-fA-F]{1,4}){1,7})
|
(((([0-9a-fA-F]{1,4}:){6})(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
((([0-9a-fA-F]{1,4}:){5}[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}))
|
(([0-9a-fA-F]{1,4}:){5}:[0-9a-fA-F]{1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,1}(:[0-9a-fA-F]{1,4}){1,4}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,3}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,2}:(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3})
|
(([0-9

The Polyglot Programmer: Mixing And Matching Languages

  

See why you need to be a polyglot programmer and what mixing and matching languages can do for your projects.

Ted Neward

MSDN Magazine March 2009


SQL Server 2005: Regular Expressions Make Pattern Matching And Data Extraction Easier

  

Now you can perform efficient, sophisticated text analysis using regular expressions in SQL Server 2005.

David Banister

MSDN Magazine February 2007


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