我有一个用于识别电话号码的正则表达式。
^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$
我想要做的是从字符串中提取所有电话号码并将其存储在数组中。 Yhis是我所做的:
var rtel = new RegExp(/^(\+\d{1,2}\s)?\(?\d{3}\)?[\s.-]\d{3}[\s.-]\d{4}$/gi)
var r = "Inthe (555)-555-5555 pavithrarox @gmail.com strings below, you 'll find that the content of each 1. abc . pavithraprbd@gmail.com line is indented by some whitespace from the index of the line (the number is a part of the text to match). Try writing a pattern that can match each line regardless of how much whitespace is between the number and the content. Notice that the whitespace characters are just like any other character and the special metacharacters like the star and the plus can be used as well.".match(rtel);
但这仅在完整字符串仅与正则表达式匹配时才匹配。如何从字符串中获取所有电话号码。我想念什么
答案 0 :(得分:2)
删除正则表达式中的<td class="no-wrap text-right circulating-supply" data-sort="17210662.0">
<span data-supply="17210662.0">
<span data-supply-container="">
17,210,662
</span>
<span class="hidden-xs">
BTC
</span>
</span>
</td>
(开始)和^
(结束)锚点。如果将它们放入,则整个字符串必须匹配。
$