Good morning
Is it a good idea to use regular expressions in C # The method is for example, if you have this string:
string s = @ "hello zone is"
There are files that we need to send to us today: & Lt; File & gt; C: \ Development \ Projects 2010 \ Accounting \ file20101130.csv & lt; / File & gt ;, & lt; File & gt; C: \ Development \ Projects 2010 \ Accounting \ Order20101130.docx & lt; / File & gt; We also want you to & lt; File & gt; C: \ Development \ Projects 2010 \ Accounting \ customersupdated.xls & lt; / File & gt; Thanks "to send;
The result will be:
c: \ development \ projects 2010 \ accounting \ file20101130.csv C: \ development \ projects 2010 \ Accounting \ orders20101130 .docx C: \ Development \ Projects 2010 \ Accounting \ customersupdated.xls
Edit: Considering what @jem said, I edit the string to add tags to make it easy to remove the required filenames from the string!
Here's something With whom I have come to:
using system; using System.Text.RegularExpressions; public class exam {public static zero main () {string s = @ "Hello John These are the files that we have to send to us today: C: \ Projects \ orders20101130.docx We also want to send you C: \ some \ file .txt, C: \ someother.file and d: \ some files \ spaces .ext thanks "; Remove (s);} Private Static Reidox Rexx Rx = New Regex (@" [ed]: \\ (?: [^ \\:] + \\) * ((?: [ ^: \\] +) \. \ W +) ", reggaeoptions. Ignorecase); Remove static zero (string text) {match match = Rx matches (text); foreign match (match match in matches) {console.wedlines (" '{0}' ", Value);}}}
produces: (see)
'c: \ projects \ orders20101130.docx', file: ' Orders20101130.docx '' C: \ some \ file.txt ', file:' file.txt '' c: \ someother.file ', file:' someother.file '' d: \ files some spaces.ext ',' File: 'with empty space .ext'
regex is not very strong (it does some assumptions), take And this has worked for your examples.
If you use the & lt; file & gt;
tag then the version of the program is Regex and Remove
:
Private static Readox Rexx Rx = New Reggae (@ " (. +?) & Lt; / file & gt; , Reggaeops's.Ignorecase); Static Zero (string lesson) {match clutter = Rx. Matches (text); Foreign match (match match in matches) {console.light line ("'{0}', match group [1]);}}
Also available in addition to this.
Comments
Post a Comment