New to REgEX and in my sixties so bear with me Using ColdFusion so presumably java version(if there is one)
Looping through some repeated text including picking up values like 4.95 and 4 from
<td align="right" >4.95</td>
<td align="right" >4</td>
using regex
.+?>(.+?)</td>.+?>(.+?)</td>
but having problems when there is no value i.e.come across string like
<td align="right" ></td>
How would I go about returning a null or 0 in this situation
TIA
Change the + to a * in the relevant places:
...(.*?)...
A .+
matches one or more characters, whereas .*
matches zero or more characters. The resulting capture will be an empty string.
Also, I'd advise against using regular expressions to parse HTML. Look to see if there is an HTML parser available in your programming language.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With