0

I need to replace a bunch of lines for SQL queries

The format is like

"xyzabcd > hdsd + 5 and",
"xzbcd_TTM_dfdfd > hdsd + 20 and",
"x_TTM_dfsddsdsdfd > hdsd + 20 and"

I need to find the keyword TTM and add a "(" at the beginning and " or some condition)" in the end but before the word "and"

So the line

"xzbcd_TTM_dfdfd > hdsd + 20 and",

becomes

"(xzbcd_TTM_dfdfd > hdsd + 20 or some condition) and

I am trying to do it in Textpad but I can also use Notepad++. Thanks a lot in advance.

Alan Moore
  • 73,866
  • 12
  • 100
  • 156
John
  • 529
  • 8
  • 20
  • `([a-zA-Z]+_TTM_[a-zA-Z]+\s+>hdsd\s+\d+)\s+and` with something like `(\1 OR some condition) and` (don't know the group placeholders in Notepad++). Best to use case-insensitive matching. –  Mar 05 '16 at 13:05
  • This didn't work unfortunately. seem I am missing something basic. As mentioned below, I tried to replace C_TTM_xxx with just to add opening parenthesis right now and replaced ._TTM with \(\1 but it replaced whole string with it. So C_TTM_xxx became (_xxx instead of becoming (C_TTM_xxx. – John Mar 05 '16 at 13:33

1 Answers1

3

For Notepad++ and for TextPad you can use

Search:

"(.+)\sand",*

Replace:

"\(\1 OR some condition\) AND
Varon
  • 3,736
  • 21
  • 21
  • Didn't work unfortunately. for example I tried to replace C_TTM_xxx with just to add opening parenthesis right now and replaced ._TTM with \(\1 but it replaced whole string with it. So C_TTM_xxx became (_xxx instead of becoming (C_TTM_xxx – John Mar 05 '16 at 13:32
  • I don't understand what you mean. Can you give a full example. For now I'm not sure if you have a `"` at beginning or not. – Varon Mar 05 '16 at 13:42
  • Nopes I don't have it. For starters, I just tried to change C_TTM_xxx to (C_TTM_xxx. but I was not able to. can you tell me how to do that. I will do the next part after I find out how to do this. – John Mar 05 '16 at 13:46
  • Search `(.*)` Replace `\(\1` will replace `C_TTM_xxx` to `(C_TTM_xxx` – Varon Mar 05 '16 at 13:48
  • Great. This worked. Thank You. There are lines without the keyword TTM too. So I replaced (._TTM*) with \(\1. Now how do I replace (C_TTM_xxx and to (C_TTM_xxx yyy and. – John Mar 05 '16 at 13:58
  • This has got a good answer. Thank you for your help. http://stackoverflow.com/questions/35817020/search-and-replace-in-textpad-notepadd-using-regex – John Mar 05 '16 at 17:18