0

Am I correct in assuming that repl.bat will not work if I'm trying to do a search & replace for a pattern that can be 3-4 lines long?

Whenever I try to use a '/s', '/n', or anything to continue the pattern search onto the next line, it fails to find any pattern at all.

e.g. SEARCHING FOR THE FOLLOWING PATTERN

    for i in range(60):
        try:
            if self.is_element_present(By.CSS_SELECTOR, "div[id=Navigation] ul[id=mainNav] a[href='/DataValues/']"): break
        except: pass
        time.sleep(1)
    else: self.fail("time out")

So when I try: type file.py | repl "\sfor i in range\(60\)\:" "cookie" file.py.new

...to represent the first line, it will find the first line successfully.

However if I add a '\n' or '\s' to continue searching for the pattern past the first line:

** type file.py | repl "\sfor i in range\(60\)\:\stry" "cookie" file.py.new **

...it fails to find anything and no changes are made. I've tried different combinations of \n and \s & the results are always the same. Thanks ahead of time for your help!

kirti
  • 4,499
  • 4
  • 31
  • 60
rwbyrd
  • 416
  • 5
  • 24
  • 2
    Where does `repl.bat` come from? – mojo Nov 03 '14 at 17:50
  • My apologies (https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat). – rwbyrd Nov 03 '14 at 18:21
  • Here is the [original REPL.BAT post](http://www.dostips.com/forum/viewtopic.php?f=3&t=3855), and here is the [earliest StackOverflow post](http://stackoverflow.com/a/16735079/1012053) – dbenham Nov 03 '14 at 18:40
  • REPL.BAT has been superseded by [JREPL.BAT](https://www.dostips.com/forum/viewtopic.php?t=6044) – dbenham Nov 22 '19 at 21:44

1 Answers1

2

Read the documentation more carefully. You need the M option to be able to match across multiple lines.

For example, given test.txt

red
+
blue

Then

type test.txt | repl "red\s*\+\s*blue" "purple" m

yields

purple
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • 1
    Yikes, I feel dumb. That wasn't my whole issue, but once I got that added, I was able to figure out the rest. Thanks man. – rwbyrd Nov 03 '14 at 20:01
  • Is there any chance you might know how to get this same process to see double quotes in the search? I've tried using ' \" ' and ' "" ' to no avail. – rwbyrd Nov 03 '14 at 20:54
  • @RichieByrd - It's in the built in help doc: Option 1) use the hex escape sequence`\x22`. Option 2) use `\q` with the X option. – dbenham Nov 03 '14 at 21:00
  • Sorry, I had meant to mention I tried using \q, but that didn't work. However, \x22 appears to have done the trick. Thanks again man. – rwbyrd Nov 03 '14 at 21:09
  • @RichieByrd - `\q` works fine as long as you remember the `X` option. For your case, the trailing option string would be `MX`. – dbenham Nov 03 '14 at 21:16
  • Yeah, I figured that out after my last message and reading the documentation. Again, thank you for your help! – rwbyrd Nov 03 '14 at 22:04