Sign in to follow this  
Followers 0
Spiff59

StringRegExpReplace help

3 posts in this topic

#1 ·  Posted (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 by Spiff59

Share this post


Link to post
Share on other sites



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
;

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0