Regex removing/replacing before DB in practice...

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
liveme
Posts: 98
Joined: Thu Aug 27, 2015 5:22 pm

Regex removing/replacing before DB in practice...

Post by liveme » Mon Feb 22, 2021 1:43 am

Hi,
Looking for to use the regex or equivalent replaceText feature in order to sanitize inputs before saving to DB.

Anyone would know how to succesfully remove several symbols that I can not seem to kick out ?

the following works 90% but fails for those...

Code: Select all

  put replaceText(tFieldText,"[-$&~'#%?!@°,*+=></\(){}]","")  into field "textcleaned" 
failled to remove caracters :
>>> :

Code: Select all

  \    

(both slash are already included, but one does not get removed)
.... beside how would one includes the brackets and the ' " ' symbol ?
>>>

Code: Select all

 ' ['  , ']'  ,' " ' 


Thanks for any help

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 817
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Regex removing/replacing before DB in practice...

Post by Thierry » Mon Feb 22, 2021 10:32 am

Hi liveme,

Code: Select all

Your orignal regex:
[-$&~'#%?!@°,*+=></\(){}             ]

The new one:
[-$&~'#%?!@°,*+=></\(){} \\ [\] \x22 ]
I've added some spaces to draw attention,
please drop them in your code.

\\ will match any \
[\] will match [ and ]
\x22 is the hex value for the double quote

not tested!

HTH,

Thierry
Thierry Douez
- Senior computer scientist
- Conseil, dévelopement et support en Français
https://sunny-tdz.com
https://sunny-tdz.com/livecode/externals

liveme
Posts: 98
Joined: Thu Aug 27, 2015 5:22 pm

Re: Regex removing/replacing before DB in practice...

Post by liveme » Tue Feb 23, 2021 8:54 am

Thanks a lot Thierry for showing me the correct way !
...no problem, I ll test it !
Great great :wink: !

Works perfectly !
Last edited by liveme on Tue Feb 23, 2021 9:06 am, edited 1 time in total.

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 817
Joined: Wed Nov 22, 2006 3:42 pm
Location: France
Contact:

Re: Regex removing/replacing before DB in practice...

Post by Thierry » Tue Feb 23, 2021 9:05 am

liveme wrote:
Tue Feb 23, 2021 8:54 am
Thanks a lot Thierry for showing me the correct way !
...
You're welcome.

If you find anything wrong or unclear, please let us know...

Regards,

Thierry
Thierry Douez
- Senior computer scientist
- Conseil, dévelopement et support en Français
https://sunny-tdz.com
https://sunny-tdz.com/livecode/externals

Post Reply

Return to “Databases”