Regex: Match the text before the end of line?

S+$ should do it with multiline functionality enabled. (Not sure how exactly you enable regex flags in... C#, is it? , but prepending (?m) to the string works with some regex engines, though it's not the only way to do it.) S matches any non-whitespace character indicates that the preceding regex element should be matched one or more times $ indicates matching to the end of the string, or end of a line if multiline is enabled EDIT: You're checking each line individually, so no need to worry about multiline stuff (Though as stated by others, going with regex for this is probably making things more complicated than necessary.

).

S+$ should do it, with multiline functionality enabled. (Not sure how exactly you enable regex flags in... C#, is it? , but prepending (?m) to the string works with some regex engines, though it's not the only way to do it.).

\S - matches any non-whitespace character + - indicates that the preceding regex element should be matched one or more times $ - indicates matching to the end of the string, or end of a line if multiline is enabled. EDIT: You're checking each line individually, so no need to worry about multiline stuff.(Though as stated by others, going with regex for this is probably making things more complicated than necessary.).

Thanks.. Yeah I think I realize that now.. :) – Colton Jul 25 at 21:25.

I think that you're making this more complex than it really is; for instance, the following should help you removing the last part of the data if formatted as per your example, with a little tweaking, such as trimming (and, obviously, error mitigation), I'm sure this would suit: var lines = new List(File. ReadAllLines(path)); for (int I = 0; I LastIndexOf(" "); if (idx! = -1) { linesi = linesi.

Remove(idx); } } Note that it is possible to read all lines of a file in one fell swoop, this isn't always desired depending on the size of the file to be loaded, but I see you're loading each of the lines anyway before processing - in which case we can just make the whole thing more concise.

I get an error stating: "StartIndex cannot be less than zero. Parameter name: startIndex" on the line linesi = linesi. Remove(idx);.

I also added the line richTextBox1. AppendText(lines + "\n"); to your code above.. – Colton Jul 25 at 21:23 @Colton Yes, proper checking would be required to prevent error; in this case, it would be that idx! = -1.

– Mr. Disappointment Jul 25 at 21:26 @Colton Furthermore, lines + "\n" won't really work, since lines is a List, you use linesi. Better yet, use linesi + Environment.NewLine. – Mr. Disappointment Jul 25 at 21:29 I updated my code above using an if statement.. However, now the richTextBox1 reads "System.Collections.Generic.

List`1System. String". Do you know how to fix this?

– Colton Jul 25 at 21:32 Your linesi + Environment. NewLine works... However, I am still getting the endings that were to be removed showing up – Colton Jul 25 at 21:34.

Just relying on the fact that each column is separated by spaces you could use: \s+(\S*)$.

Thanks, but I think I am going to try a simpler way then REGEX. – Colton Jul 25 at 21:25.

Reads the lines in the file to format. Var fileReader = File. OpenText(filePath + "\\Remove Package 1 Endings.

// Creates a list for the lines to be stored in. // Adds each line in the file to the list. Match theRegex = Regex.

// Removes the matched values from both of the Regex used above. List userResult = mainResult. // Prints the proper values into the assigned RichTextBoxes.

Can anyone help come up with a regex for this? Var lines = new List(File. ReadAllLines(filePath + "\\Remove Package 1 Endings.

For (int I = 0; I AppendText(linesi + Environment.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions