1

I am currently trying to find

\000\000\001\031704_news_release.pdf

Which I have successfully done with

000\\000\\\d\d\d\\

I am pretty sure I am doing something wrong here though because I want to replace with a return (\r) but when I run the replace the last set of 3 digits get erased.

So the desired output would be

\000\000\001\

031704_news_release.pdf

For reference I am running the following as my replace currently

000\\000\\\1\2\3\\\r

Any ideas?

  • Can you post us your search param too? – LPChip Jul 30 '15 at 21:03
  • Do you mean what I am using as my find? Thats 000\000\\d\d\d\ – Josh Jul 30 '15 at 21:32
1

Well, you haven't captured anything to store to be referenced by the \1 and \2 and \3 that's why you appear to lose things when you try to refer to them in the replace.

Use round brackets(parentheses) in the find section around what you want to keep for \1 and \2 and \3 like this

It's not quite clear what you want to do, but here's an example

And you wouldn't want just \r in the replace.. i've included that error of yours in the example and it somehow made a new line. But you should be doing either \n(a unix line ending) or \r\n(a windows line ending) to make that new line/line separator/line terminator.

enter image description here

And if you want to be more concise with your regex

FIND: (0{3}\\){2}\d+\\

REPLACE: $0\r\n

Note that you can easily use $0 in your example regex. It means the whole matching

So for your one, you could've done

FIND: 000\\000\\\d\d\d\\

REPLACE: \0\r\n

enter image description here

  • \r is the EOL marker for Mac OS (up to version 9) – DavidPostill Jul 30 '15 at 22:14
  • Ah, I knew I was doing something wrong. Thanks! – Josh Jul 30 '15 at 22:18
2

Try this for your search text:

000\\000\\(\d+)\\ or this 000\\000\\(\d\d\d)\\

And this for your replace text:

000\\000\\\1\\\r or 000\\000\\\1\\\n

In order to replace text in a regular expression, you need to identify what you want to replace. You were just missing the parenthesis. The parenthesis identifies the enclosed regular expression as the "capture" text. Take a look here for a more thorough explanation: http://www.regular-expressions.info/brackets.html

Also, I recommend taking a look at a free regex tool called Expresso from Ultrapico: http://www.ultrapico.com/Expresso.htm

  • Although this answer is correct, you may want to make it a habit of explaining why something works. By doing so, it is more likely that your answer will receive up-votes and marked as the answer. I'll upvote this post to motivate you. – LPChip Jul 31 '15 at 6:51
  • @LPChip also if giving him advice re this, re an answer being accepted, another factor, besides explanation, can be who got there first.. I also beat him to it by 1min with my ninja typing speed. – barlop Jul 31 '15 at 9:51
  • 1
    And even before just any explaining, it's definitely important to point out exactly what the OP is doing wrong. It gives much more clarity in the Q n A – barlop Jul 31 '15 at 10:07

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.