0

I'm trying to store Regex values in the DB, later to be used for custom validation. I'm storing a Regex like this:

[a-zA-Z\''\"]+

(Two single qoutes in order to get one in the DB):

[a-zA-Z\'\"]+

When i extract this regex, I get an error while Filling the dataset:

Incorrect syntax near '\'. Unclosed quotation mark after the character string ']+''.
UPDATE #TEMP2 SET CandidateNameRegex='[a-zA-Z\'\"]+'

I've tried different variations:

'[a-zA-Z\''\"]+'
'[a-zA-Z\''\""]+'
'[a-zA-Z\''\\"]+'
'@[a-zA-Z\''\"]+'
'[a-zA-Z\'\"]+'

But none seem to do the trick.

So, How do we extract single quote from the DB without breaking the string?

yaron hochman
  • 207
  • 1
  • 3
  • 7
  • If all else fails, you can also encode your data before you put it into the database, and then decode it when you take it out and this will avoid any problems you have with quotes: [Base64 Encode/Decode](http://stackoverflow.com/a/11743162/1243316) – Brad Rem Dec 24 '14 at 15:46
  • Check Brad Waite's comment on the question here http://stackoverflow.com/questions/1586560/how-do-i-escape-a-single-quote-in-sql-server Not going to put in an answer because I'm just guessing. Hope it helps – Steve Mitcham Dec 24 '14 at 15:51
  • So it looks like all you have to do is `'[a-zA-Z''"]+'` or `"[a-zA-Z'""]+"` –  Dec 24 '14 at 17:54
  • Thanks for the tips, I'll check them out and tell you if any of them works out. – yaron hochman Dec 25 '14 at 12:23
  • Finally I got it to work by writing an UPDATE command with: "[a-zA-Z''''"]+" (4 single quotes) – yaron hochman Dec 29 '14 at 09:12

0 Answers0