.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

How to extract City State Zip using Regex match

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

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!

RegEx Request - Extract an tag from string...

Hello, Can anyone give me a regular expression that will extract the <img> tag from a string.  I am receiving descriptions from an rss feed and the description contains an <img> tag in the text.  I want to extract the <img> so that I can display it in a different location on my page. I have fooled with some regular expressions, but my knowledge of them is not very good. Thanks in advance for any help!!

SharePoint 2010 - The license state for the current server doesn't match the farm's license state.

I already have a SharePoint 2010 server built, up and running. Yesterday I built a brand new server Windows 2008 and installed all necessary windows updates. Then I joined the server to the domain where the other SharePoint 2010 box is. Today, I installed all necessary pre-requisites for SharePoint 2010 including the KB971831. After that I installed SharePoint 2010 binaries on the new server. When I run the configuration wizard now, it sees the database server with the configuration database, but will not allow me to join the new server to the farm. I get the following error in the diagnostic logs. Resource retrieved id ConfigurationDatabaseTaskConnectFailConfigDisplayLabel is Failed to connect to the configuration database. 02/18/2010 17:54:12 8 INF Leaving function StringResourceManager.GetResourceString 02/18/2010 17:54:12 8 ERR Failed to connect to the configuration database.   An exception of type System.InvalidOperationException was thrown. Additional exception information: The current server cannot be joined to this farm because the set of installed products does not match the products installed in the farm.   The license state for the current server doesn't match the farm's license state. System.InvalidOperationException: The current server cannot be joined to this farm because the set of installed products does not match the products installed in the farm.

Extract String using RegEx

HelloI have below data in string format in a field in table and would like to parse the name from the quantity. The name should be anything before it hits a numeric numberin below example CHLORPHENIRAMINE is the name. i really appreciate if i can get a regex to extract the name from below string                                    "CHLORPHENIRAMINE 8MG CAP SA",                                    "CHLORPHENIRAMINE 12MG CP SA",                                     "CHLORPHENIRAMINE 4MG TABLET",                                     "CLEMASTINE FUM 2.68MG TAB",             &n

The license state for the current server doesn't match the farm's license state.

Help!!!! I removed project server 2010 from my server hosting SP 2010 and when I run the config wizard I get the error The license state for the current server doesn't match the farm's license state.  I need to bring it back online asap... :(  Any ideas please.

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.

Having trouble creating RegEx to extract value from GridView row

Hey Everyone,
Since I had such great help with my first RegEx problem I thought I'd give it a second try. This one is a fair bit more complicated. I need to extract a value from within an onclick attribute of an input (button) in a the row of a grid that contains a column that contains certain text. Here is the html: 

<tr class="rgRow" id="ctl00_ContentPlaceHolder1_OrganizationsRadGrid_ctl00__24">

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


Help in writing a funcion in Splitting Address field into City,state and zip in SQL


Hi All,

I have to split a column into  city/state/zip.
MACON GA 31220
ORLANDO, FL. 32817


city state zip

MACON GA 31220


I tried 2 cases:

declare @s varchar(100)
select @s = 'Los Angeles, CA 90022'
select charindex(',',@s)
CITY = substring(@s,0,charindex(',',@s))
,STATE = substring(@s,charindex(',',@s)+1,len(@s)- (charindex(',',@s)+1 + 5))
,"ZIP CODE " = RIGHT(@s,5)

declare @s varchar(100)
select @s = 'Los Angeles. CA 90022'
select charindex('.',@s)
CITY = substring(@s,0,charindex('.',@s))
,STATE = substring(@s,charindex('.',@s)+1,len(@s)- (charindex('.',@s)+1 + 5))
,"ZIP CODE " = RIGHT(@s,5)


Thanks ,


Does Regular Expression (RegEx) able to extract Sentence from paragraphs



I am new to Regular languages; I have been trying to find out whether Regex is able to extract sentences from any paragraph (text) on PDF format based on particular words (pattern).



Can you please outlines this with example in C#


Thank you in advance  

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

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.



REGEX to extract fourth and fifth position in a word



Was looking for regex to extract letters from fourth and fifth position in a word. (Word can have numbers followed by words)

ABCDEFGH111XYZ should return DE

COLDCOLD81928TEST should return DC

ANILANILTEST128ANIL should return LA

Appreciate all your help/support in advance.





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.

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