<html>
<head>
<base href="https://bugs.documentfoundation.org/">
</head>
<body>
<p>
<div>
<b><a class="bz_bug_link
bz_status_UNCONFIRMED "
title="UNCONFIRMED - REGEX() function with an integer as 'Occurence' returns the complete 'Text' if the respective match doesn't exist. It should return #N/A."
href="https://bugs.documentfoundation.org/show_bug.cgi?id=126764#c1">Comment # 1</a>
on <a class="bz_bug_link
bz_status_UNCONFIRMED "
title="UNCONFIRMED - REGEX() function with an integer as 'Occurence' returns the complete 'Text' if the respective match doesn't exist. It should return #N/A."
href="https://bugs.documentfoundation.org/show_bug.cgi?id=126764">bug 126764</a>
from <span class="vcard"><a class="email" href="mailto:erack@redhat.com" title="Eike Rathke <erack@redhat.com>"> <span class="fn">Eike Rathke</span></a>
</span></b>
<pre>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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>