Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

URGENT:  Please help with Regular Expression modification

Posted on 2004-09-09
23
Medium Priority
?
270 Views
Last Modified: 2012-05-05
afilename=Regex.Match(decodedUrl, @"(?<=\w+\:\s+)\w\:\S+(?=\s|\.eml)", RegexOptions.ExplicitCapture|RegexOptions.IgnoreCase).Value;

used to work just fine when the Subject line of the e-mail file was:

"Failure:  C:\12341234123432.doc"


But now the Subject line of the e-mail has changed to this:

"Failure:  \\platinum\FaxCOMGeneratedFaxes\12341234123432.doc"


What I am after is JUST this part:


12341234123432.doc



The rest of the subject line can be discarded.



Thank you,


Tom



0
Comment
Question by:Tom Knowlton
  • 9
  • 7
  • 5
  • +2
23 Comments
 
LVL 5

Expert Comment

by:tomasX2
ID: 12021925
Maybe not what you need but here is a solution without  regex...
                  string url = "\\platinum\FaxCOMGeneratedFaxes\12341234123432.doc";
                  string whatINeed = s.Substring(s.LastIndexOf(@"\"));
0
 
LVL 5

Accepted Solution

by:
tomasX2 earned 2000 total points
ID: 12021933
Comment from tomasX2
Date: 09/09/2004 03:00PM PDT
 Your Comment  


Maybe not what you need but here is a solution without  regex...
               string url = "\\platinum\FaxCOMGeneratedFaxes\12341234123432.doc";
               string whatINeed = url .Substring(url .LastIndexOf(@"\"));
 
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12021988
Expert tomasX2:

This looks promising.

The problem is I have not had a chance to study Regular Expressions or WebDAV  (YET)   so I am lost whenever modifications are required!!!!!

Thanks...I'll let you know how this works out.

Tom
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12022107
Expert tomasX2:

Your proposed solution was right on the money.....I just need you to help me tweak it some more.

I found out that the URL line looks like THIS:

http://www.buyersfund.com/exchange/faxcom/FaxMakerFaxes/Success: \\platinum\FaxCOMGeneratedFaxes\040909160209703.doc (Fax sent to 917135326577).EML


Which when I run LAST INDEX OF on the above line I get:


\040909155232735.doc (Fax sent to 918165240579).EML


NOTE:  I was wrong about what I said I needed earlier (sorry abou that).

What I need is to parse the line in such a way so I can extact the following from it:

\\platinum\FaxCOMGeneratedFaxes\040909160209703.doc
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12022600
Here is the regex...

Regex regex = new Regex(
    @"(?<doc>\\\\.*\.doc)\s+(?<eml>.+\.eml)",
    RegexOptions.IgnoreCase
    | RegexOptions.Multiline
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

then you can run:

Matches matches = regex.Matches( decodeUrl );
afilename = matches[0].Value;

Give it a try...
0
 
LVL 10

Expert Comment

by:eternal_21
ID: 12022616
Couldn't you use something real simple like:

  afilename = Regex.Match(decodedUrl, @"(?<=[^:]*\s)[^\s]*", RegexOptions.ExplicitCapture|RegexOptions.IgnoreCase).Value;
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12022630
Actually if you just need the doc you could do...

afilename = Regex.Match(dcodeUtl, @"(\\\\.*\.doc)",
RegexOptions.ExplicitCapture|RegexOptions.IgnoreCase).Value;
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12022637
Woops, should read

afilename = Regex.Match(dcodeUrl, @"(\\\\.*\.doc)",
RegexOptions.ExplicitCapture|RegexOptions.IgnoreCase).Value;
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12024311
I would suggest that use the same regular expression which you were using
but before that do what is present in the first comment from tomasX2

0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12024786
     string url = @"http://www.buyersfund.com/exchange/faxcom/FaxMakerFaxes/Success: \\platinum\FaxCOMGeneratedFaxes\040909160209703.doc (Fax sent to 917135326577).EML";
      string filePathAndSomeExtraInfo = url .Substring(url.IndexOf(@"\"));
      string whatINeed = filePathAndSomeExtraInfo.Substring(0,filePathAndSomeExtraInfo.IndexOf("(")).Trim();
      System.Diagnostics.Debug.WriteLine(whatINeed);
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12026809
Expert tomasX2's alternative to RegEx worked just fine.  Alteast I can understand what is happening now.

Regular Expression syntax is hard to understand for the uninitiated (me).
0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12026926
I agree... Regular Expressions can be frustrating....

nonetheless here is neat tool that can be used to create and test the expressions.

http://www.codeproject.com/dotnet/Expresso.asp
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12027070
I went to this link:

http://www.codeproject.com/dotnet/Expresso.asp

Very very cool.  I will have to download and try it out!!!

I can see that Regular Expressions are very powerful and cool.  Sort of a parsing "short hand" of sorts??????

I just find statements like this so intimidating:

@"(?<doc>\\\\.*\.doc)\s+(?<eml>.+\.eml)",


It just looks like a bunch of nonsense to me!!!!!!

I know you have to pick it apart and look at each character sequence one by one...and then it makes sense.....but taken as a whole I don't see how you could possibly understand what the above statement is supposed to do.  :)
0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12027125
@"(?<doc>\\\\.*\.doc)\s+(?<eml>.+\.eml)", looks like jiberish or some kind of math syntax;-)
... very unintuitive

 but you can do things with regualar expressions that are just not possible or extremly difficult with regular string manipulations.
but they are definently not always needed.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12027239
@"(?<doc>\\\\.*\.doc)\s+(?<eml>.+\.eml)", looks like jiberish or some kind of math syntax;-)
... very unintuitive

 but you can do things with regualar expressions that are just not possible or extremly difficult with regular string manipulations.
but they are definently not always needed.

============================

Agreed on all counts!

Thanks again!

Tom
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12027247
True, regular expression take awhile to get used to... but they are extreamly powerfull!  And with a little "math syntax" ;-) can do a great deal of stuff with a string.  The expresso tool is good, it is what I use to test my regex... It also will give the the C# or VB.Net syntax once you have the regex built like you want...

Let me break down  @"(?<doc>\\\\.*\.doc)\s+(?<eml>.+\.eml)" ...

the @ before the quote is a C# syntax, which sais to process the string literally.

the ( ) paren in a regex means to remember what was found
the ? in the ( ) means that the name of the match will follow in < >
the first \ means to escape the next special regex character, which is another \ in this case so the \\\\ renders to \\ when the regex is processed.
      also the \. renders to a .
the . means match any character
the * means match 0 or more times
the + means match 1 or more times
what this leaves is the \s which is a special way of saying any white space in regex.


So (?<doc>\\\\.*\.doc) will match \\platinum\FaxCOMGeneratedFaxes\040909160209703.doc putting it into a group called doc
     (?<eml>.+\.eml) will match (Fax sent to 917135326577).EML putting it into a group called eml

So while a regex can look like a math equation it can be every bit as powerful for manipulating a string.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12027527
The great appeal of RegEx is the brevity, to be sure.

I just have to practice, right?  :)

0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12027560
Getting a good book on Regular Expressions might help a lot also... O'REILLY puts out a good one that I would recommend.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12045313
NipNFiar:

Can you give the exact title / auther of the book and I will check it out!

I do have the "camel" book on Perl, btw.  Would you still recommend the other book?

I will be working in C# quite a bit this next year....is there a C# specific book on RegEx?
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12054868
Here is a link to the book:  http://www.oreilly.com/catalog/regex2/index.html

Also, yes I would still recomend the book... The reason is that this book deals with a number of subtleties in regular expressions where as most other books deal with syntax.

I cut my teeth on regular expressions with the "camel" book while I was developing heavely with PERL.  It is a decent resource...

The two books that I have used the most for .Net development are:

"Applied Microsoft .NET Framework Programming" by Jeffery Richter and "Inside C#" by Tom Archer and Andrew Whitechapel both published by Microsoft Press.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12055554
The two books that I have used the most for .Net development are:

"Applied Microsoft .NET Framework Programming" by Jeffery Richter and "Inside C#" by Tom Archer and Andrew Whitechapel both published by Microsoft Press.

===================

Please tell me a little bit about these books, especially "Inside C#".  What is the intended purpose of the "Inside C#" book?
0
 
LVL 7

Expert Comment

by:NipNFriar_Tuck
ID: 12055896
The main thrust of Inside C# is as an Architectural Reference.  Some of the advanced programming topics covered include UnManaged Code, Remoting, Threading, Security, Error Handling and more.

The Applied Microsoft .NET Framework Programming covers .NET topics that are a part of the core framework and is language agnostic.  Some of the topics that I found usefull here include Reflection, Delegates and how the .NET Garbage Collection works.

While I come from more of a Java background and was able to apply 90+ percent of that knowledge to C#, these books have filled in the gaps nicely.
0
 
LVL 5

Author Comment

by:Tom Knowlton
ID: 12055998
Cool.

I come from the following background:

C++
Delphi
Visual Basic / MS Access / VBA / Office Automation

I started out at the company I now work for programming in MS Acccess.

We are moving from MS Access to a WEB-based application.  I am doing less and less in MS Access and more and more in C# as time progresses.  The intention is for me to write the middle tier of our WEB-based application, between the Web GUI and SQL Server database.

I have it as my personal goal to learn C# inside and out.....to master the language.  I am just trying to figure out the best way to do that.  Obviously....just by writing applications in the language I can learn it over time.....but my boss has approved ONE hour a day to spend on *just* learning the C# language.....so I am trying to figure out the BEST way to spend that hour.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question