Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

URGENT:  Please help with Regular Expression modification

Posted on 2004-09-09
23
264 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: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 500 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: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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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