Example HTML:
<root>
<td><p><b>Random Text</b></p>
<p><b>Random Text:</b> Random Text</p>
<p><b>Random Text:</b> 001057567</p>
<p><b>Random Text:</b> Random Text</p>
<p><b>EXAMPLE:</b> 00887546858</p>
</td>
</root>
I need to match the
element that contains "EXAMPLE" and a random number, but I need "EXAMPLE" to be case-insensitive and a whole word only (it must either be the first word in a string or be both preceded and followed by a space or any punctuation mark).
It must be an XPath 1.0 query because the environment I'm working in doesn't support newer XPath versions.
Right now, I have this query:
//*
[contains(., 'EXAMPLE') and translate(., translate(., '0123456789', ''), '') != '']
[not(
*[contains(., 'EXAMPLE') and translate(., translate(., '0123456789', ''), '') != '']
)]
It only searches for elements that contain EXAMPLE capitalized and regardless of whether it's a whole word or not.
I need to be able to match such cases too:
<root>
<td><p><b>Random Text</b></p>
<p><b>Random Text:</b> Random Text</p>
<p><b>Random Text:</b> 001057567</p>
<p><b>Random Text:</b> Random Text</p>
<p><b>for eXaMpLe:</b> 00887546858</p>
</td>
</root>
or
<root>
<td><p><b>Random Text</b></p>
<p><b>Random Text:</b> Random Text</p>
<p><b>Random Text:</b> 001057567</p>
<p><b>Random Text:</b> Random Text</p>
<p>test,eXaMpLe:00887546858</p>
</td>
</root>
But at the same time, I need to skip such cases:
<root>
<td><p><b>Random Text</b></p>
<p><b>Random Text:</b> Random Text</p>
<p><b>Random Text:</b> 001057567</p>
<p><b>Random Text:</b> Random Text</p>
<p><b>534534tretetEXAMPLE:</b> 00887546858</p>
</td>
</root>
or
<root>
<td><p><b>Random Text</b></p>
<p><b>Random Text:</b> Random Text</p>
<p><b>Random Text:</b> 001057567</p>
<p><b>Random Text:</b> Random Text</p>
<p><b>EXAMPLE00887546858</p>
</td>
</root>
I asked ChatGPT about the solution numerous times, but it keeps providing incorrect answers that either don't match anything on the page or match the whole body.