45977

Regex, Finding a single quote enclosed by single quote

I am maintaining an old system that have saving issue when a string contains a single quote.

For example these will fail:

"update table set column2 = 'O'Connell', column3 = 'O'Riordon' where column1 = 1" "insert into table (column1, column2, column3, column4, column5, column6, column7) values('O'Reilley','state, postcode','',1,2,'O'Riordon')".

So far I've came up with this working vbscript regular expression

([,=(]\s*'[^']*)'([^']*'\s*[,)\s])

Is it possible to write a vbscript regular expression without using the header [(|=|\s|,] and trailer [,|)|\s]?

Thanks.

EDIT: Fix the posted regex to remove | from header and trailer. The regexp is used as follows

regexp.replace("string","$1''$2")

Answer1:

The only way I can think of works only if the string that contains the single quote never contains whitespace. In that case, you can search for

\B'([^'\s]*'[^'\s]*)'\B

<strong>Explanation:</strong>

\B # Assert that there is no alphanumeric character before... ' # the opening quote ( # Match and capture... [^'\s]* # Any number of non-quote/non-whitespace characters ' # One quote [^'\s]* # Any number of non-quote/non-whitespace characters ) # End of capture group 1 ' # Match the closing quote \B # Assert that there is no alphanumeric character afterwards

Recommend

  • how to perform sum on average on distinct different then the group field
  • Insert with Select give sql-error (SQLCODE=-803, SQLSTATE=23505)(db2 z/os)
  • T-SQL Column values count
  • including classes with a wsc file
  • Datatable don't create certain rows
  • Search formula for cell references in VBA
  • How to debug ASP permission problems with WScript.Shell object?
  • mysql query with WHERE IF and FIND_IN_SET() function
  • plsql procedure to compare two tables where structure of table is not known
  • How to debug ASP permission problems with WScript.Shell object?
  • Utilize ADO.NET within Classic ASP script
  • vbscript to change DNS server
  • InstallShield Automation can't create object
  • List Separator script
  • Reading text file in Matlab results in unknown spaces within characters
  • VB Script code not calling c# function
  • VB script error path Path not found(800A004C)
  • How to pass all columns except one as argument to setkey()?
  • Using HTA in vbscript
  • How to get WMI object from a WMI object reference
  • Excel VBA: search a string to find the first non-text character
  • PHP code to check country from IP
  • vbscript syntax in asp classic
  • CRLF in VBScript
  • How to filter a range by first Character in a cell?
  • Handling null values with wso2 CEP
  • Access VBScript variable within Javascript inside of an HTA
  • Index Multiple Columns w/ Ruby on Rails
  • How to specify a multi-column UNIQUE constraint in code-first Entity Framework fluent API
  • Select from table that does not exist
  • Eloquent Relationship on Partial Match
  • in batch how do i use taskkill properly
  • converting text file into xml using php?
  • PHP - How to update data to MySQL when click a radio button
  • Join two tables and save into third-sql
  • How to handle AllServersUnavailable Exception
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • Hits per day in Google Big Query
  • File not found error Google Drive API
  • Converting MP3 duration time