Question

I'm trying to use a regex to match a block of text, and using replace all, replace it with nothing, so as to delete it.

But Since I sometimes (but not always) have the block appear one after another when I try to replace all, it replaces every second block.

I made this Regex

http.*\n.*\K\n\{\n  "code"(.*\n)+?\}\nhttp.*\n

But it will match all isolated blocks, but only every second consecutive block. I think I'm meant to use "assertions" as described by here. But I couldn't get them to work.

Also how do I replace with nothing (as in delete)? Just leave an empty replace with field? or do I need some special character? Or as I am coming to suspect, I shouldn't use Notpad++ for this sort of thing? If that is the case what should/could I be using?

Sample Data:

  "teamAbbr" : "Foo",
  "teamName" : "Bar",
  "teamNickname" : "FBar"
    }
  } ]
}
http://www.link_I_want_to_keep_belonging_to_above_data.com

{
  "code" : "XXXXXXXXXXXXXXXXXXXXXXX",
  "techMessage" : "XXXXXXXXXXXXXXXXXXXXXX",
  "userMessage" : "XXXXXXXXXXXXXXXXXXX",
  "host" : "XXXXXXXXXXXX",
  "date" : "XXXXXXXXXXX",
  "version" : "XXX"
}
http://www.url_that_belong_to_block_Iwant_to_be_rid_off.com

{
  "code" : "XXXXXXXXXXXXXXXXXXXXXXX",
  "techMessage" : "XXXXXXXXXXXXXXXXXXXXXX",
  "userMessage" : "XXXXXXXXXXXXXXXXXXX",
  "host" : "XXXXXXXXXXXX",
  "date" : "XXXXXXXXXXX",
  "version" : "XXX"
}
http://www.url_that_belong_to_block_Iwant_to_be_rid_off.com
Was it helpful?

Solution

The problem is that you also match the first url, but that is unavailable when immidiately after a match. And also at the start of the file.

Lookbehind assertions takes care of the problem, but needs to be fixed length.

Do you need to search for the first url? Ie. does

\{\n  "code"(.*\n)+?\}\nhttp.*\n

work for you?

To delete a whole match you replace with an empty string. No special characters needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top