Pregunta

Consider the regular expression \d*

If I try to match this against the string JJJ123, Vertica's regex functions say it matches against the string of width zero at the beginning.

If I try it instead in matlab, it reports a match starting at the character 1.

The Vertica docs say that its regex engine is PCRE. I can't find much on matlab's, though I found hints that it's similar to perl's.

Which of the behaviors is more standard for perl-like regex engine?

¿Fue útil?

Solución

Matlab's regexp has an emptymatch option that controls whether it will allow an entire regex expression to match an empty string. It is off ("noemptymatch") by default. See help regexp.

Vertica's matching the 0-length empty string at the beginning is normal behavior for most regex dialects that I know, including anything Perl-like.

To get the same behavior as Vertica, where it can match 0-length strings, pass the 'emptymatch' option in your regexp call. Also pass 'once' to prevent it from matching the empty spaces between each and every character in your string.

[a,b,c,d] = regexp('JJJ123', '\d*', 'emptymatch', 'once')
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top