0

I would like to use regular expressions (.NET) for the following task.

A text file contains the following lines:

=650  \1$aPets$xFiction.  
=650  \1$aApartment houses$xFiction.  
=650  \0$aPets$xFiction.  
=650  \0$aApartment houses$xFiction.

The regex should identify the cases where lines are identical except for the 8th character (0 vs. 1), & then delete the lines where the 8th character is a 1.

Output would then be:

=650  \0$aPets$xFiction.  
=650  \0$aApartment houses$xFiction.  

(with the rest of the text file unchanged)

If other tools or techniques would be preferable, I'd be happy to learn about those.

Thank you.

Ricardo Alvaro Lohmann
  • 26,031
  • 7
  • 82
  • 82
whuffo15
  • 29
  • 1
  • 3
  • Now you should try getting a regex for it. Then try writing the .NET code to do it. Without trying anything, don't ask a question here. Come back when you have some doubt in the regex you have come up with or when the .NET code doesn't do what you want it to do. – manojlds Jan 14 '13 at 16:25
  • Apologies. My regex is still extremely basic -- just recently started learning/ using it -- & this particular problem is way beyond my skill level. Will give it a crack, however, & see how far I get. – whuffo15 Jan 14 '13 at 16:34
  • The regular expression pattern `^.......1` will match the string that has `1` as the 8th character. `SomeString[7]` will give you the 8th character which you can check for being `=='1'`. Can you build something around this? – Salman A Jan 14 '13 at 17:42
  • Thank you; it's a start. Pretty sure I'll be using submatch variables (backreferences) & then the replace function ... Will take me a while to get up to speed :-) – whuffo15 Jan 14 '13 at 18:21

0 Answers0