Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regex cannot to be parsed #1

Closed
upeter opened this issue Jun 11, 2015 · 3 comments
Closed

Regex cannot to be parsed #1

upeter opened this issue Jun 11, 2015 · 3 comments

Comments

@upeter
Copy link

upeter commented Jun 11, 2015

When using regular expressions in the mq interpolator a variable expected error is thrown. It seems that regex is not supported

import com.github.limansky.mongoquery.casbah._

scala> val term = "anything"
term: String = anything

scala> mq"""{naam: /^$term/i}"""
<console>:12: error: variable expected
       mq"""{naam: /^$term/i}"""

@limansky
Copy link
Owner

Good point. I'll check what I can do.

@limansky
Copy link
Owner

Sorry for long delay. As a workaround you can use it this way:

import com.github.limansky.mongoquery.casbah._
scala>  val term = "^(?i)anything".r
term: scala.util.matching.Regex = ^(?i)anything

scala> mq"""{naam: $term}"""
res3: com.mongodb.DBObject = { "naam" : { "$regex" : "^(?i)anything" , "$options" : "i"}}

Btw, for me, it's more clear usage. The reason is that we want to use regex and we passing regex. So, the regex is an atomic value, like string for example. And the behaviour is the same, you cannot combine string from the different parts like: mq{ foo : "bar$x" }. But, like for the other types it would be nice to support literals: mq{ bar : /[0-9]+/ }

So I'd like to use this issue to track regex literals support.

@limansky
Copy link
Owner

limansky commented Sep 1, 2015

Initial drop for regex literals support is available in 0.5-SNAPSHOT.

@limansky limansky closed this as completed Oct 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants