-1

I have the following code for example:

SELECT Something, ?, Count('Something2') AS Total FROM table WHERE Id=? AND Time>NOW() FOR UPDATE

Now I need to search for the ? between SELECT and FROM. How can I do that? Something like SELECT \? FROM

Jerry
  • 70,495
  • 13
  • 100
  • 144
Jordy
  • 4,719
  • 11
  • 47
  • 81
  • What do you mean "need to search" ? what are you trying to do ? – Nir Alfasi Sep 18 '13 at 16:26
  • 1
    I need to search for the '?' character within Notepad++ – Jordy Sep 18 '13 at 16:26
  • Huh? What are you trying to do? Do you want a regular expression? To determine whether there is a question mark anywhere between select and from? Or what? – Dan Sep 18 '13 at 16:27
  • 1
    If you just need to search for a literal ?, then press ctrl-f, put "search mode" to "normal", and type a ? into the box. If you want to do it with search mode still as "regular expression", then type `\?` into the search box. If you want to search for the entire string from Select to From, then use `SELECT.*?\?.*?FROM`. – Dan Sep 18 '13 at 16:28
  • did you try anything? `?` seems like an obvious thing to try, with `\?` being the next, and correct, one. – John Dvorak Sep 18 '13 at 16:29
  • 1
    Yes, you are right, but I only want to search for the ? character between SELECT and FROM, so the character after 'Id' should not show up. – Jordy Sep 18 '13 at 16:29

1 Answers1

1

Use lookahead to match only the "?"

(\?)(?=.*FROM.*)

make sure to use case-insensitive so you won't miss queries in which from is written in lower-case.

Most of the regex flavors don't support lookbehind with unfixed size - which is why you can't use the SELECT in the regex.

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • Thanks, this regular expression works with PHP, but not with the Notepad++ search function. How to solve that? – Jordy Sep 18 '13 at 16:42
  • @Jordy weird but I had the same issue yesterday (with Notepad++): http://stackoverflow.com/a/18861906/1057429 didn't get a chance to check it on another computer though... – Nir Alfasi Sep 18 '13 at 16:45
  • Strange, I updated Notepad++ to the latest version and it works now... Thanks! – Jordy Sep 18 '13 at 16:54