RegEx How to process strings with zero length?

New to REgEX and in my sixties, so bear with me Using ColdFusion, presumably the java version (if any)

Quoting through some repeating text, including selecting values ​​such as 4.95 and 4 from

<td align="right" >4.95</td> <td align="right" >4</td> 

using regex

 .+?>(.+?)</td>.+?>(.+?)</td> 

but it has problems when there is no iecome value in the string, for example

 <td align="right" ></td> 

How can I return zero or 0 in this situation

TIA

+4
source share
1 answer

Change + to a * in the appropriate places:

 ...(.*?)... 

A. .+ Matches one or more characters, while .* Matches zero or more characters. The resulting capture will be an empty string.

Also, I would recommend using regular expressions to parse HTML. See if your programming language has an HTML parser.

+7
source

Source: https://habr.com/ru/post/1341863/


All Articles