Ask for adding RegEx matches and replaceAll functions

141 views
Skip to first unread message

t603

unread,
Jul 4, 2007, 4:36:14 AM7/4/07
to H2 Database
Hello!

What about to add Java SE string functions String.matches(String
regex) and String.replaceAll(String regex, String replacement) into
built-in H2 string functions? I know I can create public static
version of these Java functions and add them into H2 as custom
function, but I think, it can be useful for general public.

Stepan

Thomas Mueller

unread,
Jul 9, 2007, 3:34:30 PM7/9/07
to h2-da...@googlegroups.com
Hi,

OK, I will add a feature request. In some situations it is possible to
use an index for MATCHES, so it really makes sense to add it to the
database core. How should the methods be called?

Suggestion: expression REGEXP matchExpression
Java: String.matches
PostgreSQL: expression ~ matchExpression
MySQL: expression REGEXP matchExpression
Oracle: REGEXP_LIKE(.., ..)

Suggestion: REGEXP_REPLACE(expression, regex, replacement)
Java: String.replaceAll
PostgreSQL: REGEXP_REPLACE
Oracle: REGEXP_REPLACE

Thomas

t603

unread,
Jul 10, 2007, 3:43:31 AM7/10/07
to H2 Database
Hi,

On Jul 9, 9:34 pm, "Thomas Mueller" <thomas.tom.muel...@gmail.com>
wrote:

> In some situations it is possible to
> use an index for MATCHES, so it really makes sense to add it to the
> database core.

I think, that RegExp should not necessary use indexes directly. It can
be done by adding LIKE by user. So something like

select name from authors where name regexp_matches '^Neu(mann|hauser|
wirth)' and name like 'Neu%'

This approach can be less painful for implementation.

> How should the methods be called?

> Suggestion: expression REGEXP matchExpression

...better: expression REGEXP_MATCHES match Expression To have
consistent name with REGEXP_REPLACE

> Suggestion: REGEXP_REPLACE(expression, regex, replacement)

...Yes.

Thank You. Stepan

Thomas Mueller

unread,
Jul 10, 2007, 3:10:06 PM7/10/07
to h2-da...@googlegroups.com
Hi,

> I think, that RegExp should not necessary use indexes directly. It can
> be done by adding LIKE by user. So something like
>
> select name from authors where name regexp_matches '^Neu(mann|hauser|
> wirth)' and name like 'Neu%'

OK, I will implement it without index usage first. Probably index
usage will be added at some point.

> ...better: expression REGEXP_MATCHES match

Yes, but this is already used by PostgreSQL (as a function). I don't
want to add a feature which would make H2 incompatible with another
database if possible.

Thomas

t603

unread,
Jul 10, 2007, 3:53:51 PM7/10/07
to H2 Database
> OK, I will implement it without index usage first. Probably index
> usage will be added at some point.

...Yes, according to demand of users and Your spare time ;-)

> > ...better: expression REGEXP_MATCHES match
>
> Yes, but this is already used by PostgreSQL (as a function). I don't
> want to add a feature which would make H2 incompatible with another

...OK, it sounds reasonable. Go for it!

Thank You. Stepan

Reply all
Reply to author
Forward
0 new messages