Spiff59 Posted July 15, 2009 Share Posted July 15, 2009 (edited) I'm writing to a database rows that include patient names. I had had brute-force code in place to handle last names like O'Conner, where the apostrophe needs to be duplicated so as not to trash the SQL statement. Then, I had an odd first name (with an apostrophe) blow up my script, so rather than duplicate the code with the loops that compare a letter-at-a-time, I thought maybe an SRER would do it. So, I need to leave apostrophes at the start of a line, adjacent to a space, comma, or parentheses, alone. I just want to dupe apostrophes that have two adjacent alpha characters. The pattern below matches correctly, but I don't know how to only capture a part of the search string, or how to insert the replacement string into the middle of the captured text. Thank you. Local $SQL[4] $SQL[1] = "Insert into CFCPAT('Williams' , 'Paul');" $SQL[2] = "Insert into CFCPAT('O'Dell','Robert');" $SQL[3] = "Insert into CFCPAT('O'Neill','T'Jae');" For $x = 1 to 3 MsgBox(1,"", StringRegExpReplace($SQL[$x], "\w'\w", "'\0")) ; MsgBox(1,"", StringRegExpReplace($SQL[$x], "(?:\w)(')(?:\w)", "\1'")) Next typos Edited July 15, 2009 by Spiff59 Link to comment Share on other sites More sharing options...
Malkey Posted July 15, 2009 Share Posted July 15, 2009 I'm writing to a database rows that include patient names. I had had brute-force code in place to handle last names like O'Conner, where the apostrophe needs to be duplicated so as not to trash the SQL statement. Then, I had an odd first name (with an apostrophe) blow up my script, so rather than duplicate the code with the loops that compare a letter-at-a-time, I thought maybe an SRER would do it. So, I need to leave apostrophes at the start of a line, adjacent to a space, comma, or parentheses, alone. I just want to dupe apostrophes that have two adjacent alpha characters. The pattern below matches correctly, but I don't know how to only capture a part of the search string, or how to insert the replacement string into the middle of the captured text. Thank you. Local $SQL[4] $SQL[1] = "Insert into CFCPAT('Williams' , 'Paul');" $SQL[2] = "Insert into CFCPAT('O'Dell','Robert');" $SQL[3] = "Insert into CFCPAT('O'Neill','T'Jae');" For $x = 1 to 3 MsgBox(1,"", StringRegExpReplace($SQL[$x], "\w'\w", "'\0")) ; MsgBox(1,"", StringRegExpReplace($SQL[$x], "(?:\w)(')(?:\w)", "\1'")) Next typos Try this. ; Local $SQL[4] $SQL[1] = "Insert into CFCPAT('Williams' , 'Paul');" $SQL[2] = "Insert into CFCPAT('O'Dell','Robert');" $SQL[3] = "Insert into CFCPAT('O'Neill','T'Jae');" For $x = 1 To 3 MsgBox(1, "", StringRegExpReplace($SQL[$x], "(\w)(')(\w)", "\1\2\2\3")); 0r "\1\2'\3" Next ; Link to comment Share on other sites More sharing options...
Spiff59 Posted July 16, 2009 Author Share Posted July 16, 2009 Try this. ; Local $SQL[4] $SQL[1] = "Insert into CFCPAT('Williams' , 'Paul');" $SQL[2] = "Insert into CFCPAT('O'Dell','Robert');" $SQL[3] = "Insert into CFCPAT('O'Neill','T'Jae');" For $x = 1 To 3 MsgBox(1, "", StringRegExpReplace($SQL[$x], "(\w)(')(\w)", "\1\2\2\3")); 0r "\1\2'\3" Next ; Rats! I was on the right track, with the separate groups. At least until I thought I'd try to "not capture" a couple of them and get my string that way. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now