[Libreoffice-bugs] [Bug 126764] REGEX() function with an integer as 'Occurence' returns the complete 'Text' if the respective match doesn't exist. It should return #N/A.
bugzilla-daemon at bugs.documentfoundation.org
bugzilla-daemon at bugs.documentfoundation.org
Thu Aug 8 12:29:09 UTC 2019
https://bugs.documentfoundation.org/show_bug.cgi?id=126764
--- Comment #1 from Eike Rathke <erack at redhat.com> ---
There is no 3rd occurrence of the expression in text, hence nothing is
replaced. This essentially is similar to =REGEX("a";"b";"") and is standard
replacement behaviour in tools like sed and awk, if there is no match then
nothing is replaced. Specifically gawk's gensub() that knows the occurrence
parameter as well behaves the same:
gawk -e '{print gensub(/b/,"",1)}'
Try with different input of "a" and "b".
If you need to check if there actually is a 3rd occurrence to be replaced then
do an explicit check:
=IF(ISNA(REGEX("12-34-56";"[^-]*-";;3));NA();REGEX("12-34-56";"[^-]*-";"";3))
Unconditionally returning #N/A if there is no match in the replace case IMHO is
not an option, otherwise the usual logic of replacements with regular
expressions would be negated and all replacements would have to use IFNA().
What we maybe could do is add an optional parameter to the function whether
#N/A shall be returned in replace cases or not. That would have to be hidden in
the Function Wizard and input hints as we have UI translations freeze for 6.3,
but in general would be possible even for 6.3. Earlier releases reading such
additional parameter if present of course would fail then.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20190808/b1e96363/attachment.html>
More information about the Libreoffice-bugs
mailing list