0

I am matching all date formats in my file using the regex ([0-9]+)-+([0-9]+)-+([0-9]+) now how can i delete everything else but the matches? Thanks

Here is an example

     <Data ss:Type="String">2017-03-10 15:57:34</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">0</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">Evelyne</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">Evelyne</Data>
    </Cell>
  </Row>
  <Row>
    <Cell>
      <Data ss:Type="String">170212</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">everest</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">everest</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">sdfsd@gmail.com</Data>
    </Cell>
    <Cell>
      <Data ss:Type="String"></Data>
    </Cell>
    <Cell>
      <Data ss:Type="String">2017-04-29 10:21:09</Data>

I need to delete everything but the dates in Sublime using mac, thanks.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • In Notepad++ or Sublime? Please provide an example text with expected output. In Notepad++, it can be done easily even when you have several dates on the same line, and you need to get a list of dates each on a separate line. – Wiktor Stribiżew May 11 '17 at 21:38
  • 2
    Why would that be useful? You'd be left with a list of orphaned dates that mean nothing, so this is the perfect sign that you're asking an XY question: you want to do something and you think removing all the text but the dates makes that happen. What *is* that thing, though, because there is probably a better solution than what you're currently thinking of. – Mike 'Pomax' Kamermans May 11 '17 at 21:42
  • using sublime! here is the a sample – Miro Nomadic May 11 '17 at 21:46
  • 2
    okay but the question is still: why? The data becomes meaningless numbers if you do that. Also, you're showing XML, why not just run it through an XML parser that grabs the dates and ignores everything else? Because [don't use regex to parse XML](http://stackoverflow.com/questions/8577060/why-is-it-such-a-bad-idea-to-parse-xml-with-regex). – Mike 'Pomax' Kamermans May 11 '17 at 21:54
  • Try `(?s)([0-9]+-[0-9]+-[0-9]+)|(?:(?![0-9]+-[0-9]+-[0-9]+).)+` with `$1\n`. But it is highly inefficient. – Wiktor Stribiżew May 11 '17 at 21:56
  • Perfect!! thanks @WiktorStribiżew – Miro Nomadic May 11 '17 at 22:10
  • 2
    Depending on the size of the file you could also search for the regex and click `Find All` to select only the dates and copy/paste them into another document or invert the selection and press backspace and then enter to remove everything but the dates. – OdatNurd May 11 '17 at 23:29

1 Answers1

1

In the menu: Find -> Find

Enter your regex, then press FindAll

In the menu: Edit -> Copy

Delete contents of the file

In the menu: Edit -> Paste

Andrei Cioara
  • 3,404
  • 5
  • 34
  • 62