reg expression use in web2py/dal?

53 views
Skip to first unread message

Vlad

unread,
Mar 30, 2020, 11:09:07 AM3/30/20
to web2py-users
I've got the following condition for the left join: 

left=db.auth_user.on(db.sms.sender==db.auth_user.phone)

the problem is that sms.sender is in a format like 12345678901 while auth_user.phone can be something like (234)567-8901. Doesn't have to be in any specific format, but I need to remove any non-digit characters and if it's 10 digits - to add 1. Only then the 2 strings are comparable. 

How is it possible to do it in web2py / dal?  

Vlad

unread,
Mar 30, 2020, 8:06:41 PM3/30/20
to web2py-users
Can't figure it out. Basically, I am looking for a correct way to do something like this (which is obviously incorrect, but at least expressive enough to show what's missing): 

left=db.auth_user.on(db.sms.sender==re.sub('[^0-9]','',db.auth_user.phone))

Val K

unread,
Mar 31, 2020, 3:35:03 AM3/31/20
to web2py-users
re.sub() is invoked at python level not at db level. You should use db.field.regexp(pattern)

Val K

unread,
Mar 31, 2020, 3:45:08 AM3/31/20
to web2py-users
Also you can pass raw sql string like db.field.on(raw_sql_string)

Eliezer (Vlad) Tseytkin

unread,
Mar 31, 2020, 6:38:34 AM3/31/20
to web...@googlegroups.com
Is there any example / doc on how to use regexp? It's just mentioned in the book, but no details and no samples. 

On Tue, Mar 31, 2020, 3:35 AM Val K <valq...@gmail.com> wrote:
re.sub() is  invoked at python level not at db level. You should use db.field.regexp(pattern)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/gZfpGe7EcSI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/9479f17a-0eae-449f-9d6c-b2b8bd974a3f%40googlegroups.com.

Eliezer (Vlad) Tseytkin

unread,
Mar 31, 2020, 10:25:14 AM3/31/20
to web...@googlegroups.com
I mean, I understand how to use regexp for a simple pattern matching, but here I need to use the "sub" feature. What am I missing? 

Dave S

unread,
Mar 31, 2020, 9:56:11 PM3/31/20
to web2py-users


On Tuesday, March 31, 2020 at 3:38:34 AM UTC-7, Vlad wrote:
Is there any example / doc on how to use regexp? It's just mentioned in the book, but no details and no samples. 


It depends on your db backend and the adapter.  For sqlite and the inbox-adapter, there's a python file that wraps  calls to the standard python library, which works when the sq;ite engine is local (as it usually is).  For not-so-lite DBs, I haven't had to look yet.
 
/dps

On Tue, Mar 31, 2020, 3:35 AM Val K <valq...@gmail.com> wrote:
re.sub() is  invoked at python level not at db level. You should use db.field.regexp(pattern)

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/gZfpGe7EcSI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages