1

I want to replace a regex based on a date string with the same one and a new line. The problem is that when I write the sintax like this:

Replace with : (\1)\n

Or like this :

Replace with: ($1)\n

It only replaces it with a new line, instead of replacing it with what it finds and a new line. My regex is this:

(?:0[1-9]|[12][0-9]|3[01])/(?:0[1-9]|1[0-2])/(?:19\d\d|20\d\d)

Can you help me? Or tell me what am I doing wrong?

edit:

This is a string example of what I need:

03/12/2010 lots of text 05/12/2009 lots of text lots of text 13/09/2008 lots of text lots of text lots of text 23/09/2007 lots of text 20/04/2010 lots of text

I need it to look like this:

  03/12/2010 lots of text 
  05/12/2009 lots of text lots of text 
  13/09/2008 lots of text lots of text lots of text 
  23/09/2007 lots of text 
  20/04/2010 lots of text
  • It would help if you supplied a sample of what text you are using this on, and what result you want. – GdD Jan 22 '14 at 14:53
  • i made an edit on the question, with an example – Razvan N Jan 22 '14 at 14:58
1

You are not capturing anything with that regex, just simply matching.

In that case, you would want to put the match back, so you can use $0 or \0 for that:

Replace with:

$0\n
  • Yes, that worked fine, thank you. I used it like this: \n$0, to get also the date. Thanks very much:) – Razvan N Jan 22 '14 at 15:10
  • @RazvanN Cheers :) – Jerry Jan 22 '14 at 15:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.