kservice Posted November 30, 2005 Posted November 30, 2005 Hi all, What would be the pattern for finding the last comma in a line of text? Ex: Brown, Brown, Brown, Brown, Brown, Brown Thanks a bunch! ;) Quote
mark007 Posted December 1, 2005 Posted December 1, 2005 You don't need a regex for this. Just use: Dim s As String="Brown, Brown, Brown, Brown, Brown, Brown" Dim pos as integer=s.LastIndexOf(",") :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
kservice Posted December 1, 2005 Author Posted December 1, 2005 I was looking for a regular expression because I have to replace the last comma with the word "and". I wanted to use a regular expression because I can find and replace with one line of code instead of several. Thanks for your help. :) Quote
mark007 Posted December 1, 2005 Posted December 1, 2005 Ah ok, how about: "(,)([^,]*)$" :) Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
IngisKahn Posted December 1, 2005 Posted December 1, 2005 That will give you ", Brown" I'd go with: ,(?!(?:.*,)) Quote "Who is John Galt?"
mark007 Posted December 1, 2005 Posted December 1, 2005 Well that was the point of the brackets i.e. you replace "(,)([^,]*)$" with " and $2" How does your's work Ingis? I can't say I follow it... Quote Please check the Knowledge Base before you post. "Computers are useless. They can only give you answers." - Pablo Picasso The Code Net
kservice Posted December 1, 2005 Author Posted December 1, 2005 Thanks both of you. From what you gave me I got it to work exactly like I needed. Thanks again. Quote
IngisKahn Posted December 1, 2005 Posted December 1, 2005 How does your's work Ingis? I can't say I follow it... , the comma in question (?! look ahead negative i.e. make sure this doesn't follow (?: don't save this .*, any number of charcters follwed by a comma )) Quote "Who is John Galt?"
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.