开发者

RegEx How to handle zero length strings?

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="rig开发者_如何学Goht" >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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜