Skip to content

Cosmos: Translate regex matching #28078

Closed

Description

@sekarcse

How to use RegexMatch in EF Core Cosmos C#

I want to apply the below in Linq. Here code is in-case sensitive

Cosmos Query
SELECT * FROM c
WHERE RegexMatch (c.Code, "ZWw","i")

Activity

  1. roji commented on May 23, 2022

    @roji
    Member

    This isn't currently supported, but you can use raw SQL queries to call the function in SQL yourself.

    Cosmos docs for the function

  2. sekarcse commented on May 23, 2022

    @sekarcse
    Author

    Thanks @roji for the quick reply

  3. added
    good first issue
    on May 24, 2022
  4. added this to the Backlog milestone on May 24, 2022
  5. Marusyk commented on May 25, 2022

    @Marusyk
    Member

    @roji @AndriySvyryd What is your point of view for implementing this feature?

    smth like this?

    dataSet.Where(x => EF.Functions.RegexMatch(x, "Zxw", "i"));
    
  6. roji commented on May 25, 2022

    @roji
    Member

    @Marusyk if possible, translating built-in .NET functions is preferred. For example, the PG provider supports regex by translating Regex.IsMatch(stringValue, "^A+") (see docs).

  7. AndriySvyryd commented on May 25, 2022

    @AndriySvyryd
    Member

    Adding to what @roji said you can also translate some of the options, but throw for the ones not supported by Cosmos.

    RegexOptions Modifier
    Multiline m
    Singleline s
    IgnoreCase i
    IgnorePatternWhitespace x
  8. changed the title [-]How to use RegexMatch in EF Core C#[/-] [+]Cosmos: Translate regex matching[/+] on May 26, 2022
  9. roji commented on May 26, 2022

    @roji
    Member

    Note: we also already translate Regex.IsMatch in SQLite and have tests for it in NorthwindFunctionsQueryTestBase.

  10. added a commit that references this issue on May 28, 2022
    5a9515e
  11. added a commit that references this issue on May 30, 2022
    bda79d4
  12. added and removed
    good first issue
    on May 30, 2022
  13. removed this from the Backlog milestone on May 30, 2022
  14. added this to the 7.0.0 milestone on May 30, 2022
  15. self-assigned this
    on May 30, 2022
  16. modified the milestones: 7.0.0, on Jun 20, 2022
  17. modified the milestones: , 7.0.0 on Nov 5, 2022
  18. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions