简体   繁体   中英

Return a Regex Pattern from a search in database (NodeJS)

I'm currently using Redis, but examples in any database (that are good with NodeJS) would be good to get me going.

I'm looking to find Regex Patterns from a list, by providing potential matches.

I want to query my database of patterns and ask it - "which patterns would match this string?"

Example

Pattern Database:

(\/some\/)

(\/relative\/)

(\/other\/)

Search: "/some/relative/url/"

Return:

(\/some\/)

(\/relative\/)

Search: "/some/other/url/"

Return:

(\/some\/)

(\/other\/)

So my question is: is this possible? If so, how?

This is not possible (to my knowledge) using only redis call. I suggest loading all the regular expressions from the database and running them in javascript to figure out which ones match.

I think there is a way to that. You need to treat the pattern to be stored as a string, then retrieve them as you retrieve any other string from the redis datastore. Just for your reference I am giving a link to redis-nodejs tutorial I found - Using Redis With Nodejs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM