Is there a database that can store regex as values? -


i looking database can store regex expressions values. e.g. somthing this:

{:name => "tim", :count => 3, :expression => /t+/}, {:name => "rob", :count => 4, :expression => /a\d+/}, {:name => "fil", :count => 1, :expression => /tt/}, {:name => "marc", :count => 1, :expression => /bb/} 

so return rows/documents based on whether query matches expression or not (e.g."find rows "tt" =~ :expression"). , tim , fil rows result. databases can opposite thing (check whether text field matches regex query). neither mongo nor postgres can opposite thing, unfortunately.

p.s. or perhaps wrong , there extensions postgres or mongo allow me store regex?

oracle database can that.

example query: where regexp_like(first_name, '^ste(v|ph)en$')

you want select regexp column, see sql fiddle example below example.


sql fiddle

choose oracle database.

in schema window execute following:

create table regexp (name varchar2(20), count number, regexp varchar2(50));  insert regexp values ('tim', 3, 't+'); insert regexp values ('rob', 4, 'a\d+'); insert regexp values ('fil', 1, 'tt'); insert regexp values ('marc', 1, 'bb'); commit; 

execute sql statement, e.g. (as mentioned in question):

select * regexp regexp_like('tt', regexp); 

yields:

name    count   regexp tim     3       t+ fil     1       tt 

reference here.

excerpt:

oracle database implements regular expression support set of oracle database sql functions , conditions enable search , manipulate string data. can use these functions in environment supports oracle database sql. can use these functions on text literal, bind variable, or column holds character data such char, nchar, clob, nclob, nvarchar2, , varchar2 (but not long).

and more info consider:

a string literal in regexp function or condition conforms rules of sql text literals. default, regular expressions must enclosed in single quotes. if regular expression includes single quote character, enter 2 single quotation marks represent 1 single quotation mark within expression. technique ensures entire expression interpreted sql function , improves readability of code. can use q-quote syntax define own character terminate text literal. example, delimit regular expression pound sign (#) , use single quote within expression.

note: if expression comes column or bind variable, same rules quoting not apply.

note there no column type named regex, need save string is, in textual column.

also can use regex in constraint checking , when project columns.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -