我想创建一个正则表达式来匹配Java中的一系列字符。
我有一部电话page = requests.get("https://www.bing.com/search?q=60657+weather")
soup = BeautifulSoup(page.content, "html.parser")
forecast = soup.find_all("div", {"class": "wtr_innerScroll"})
for link in forecast:
day_tabs = link.find_all("div", {"class": "wtr_forecastDay wtr_noselect"})
for day in day_tabs:
weekday = day.find("div", {"class": "wtr_weekday"})
temp_high = day.find("div", {"class": "wtr_high"})
temp_low = day.find("div", {"class": "wtr_low"})
precip = day.find("div", {"class": "wtr_daypreci"})
print(weekday.text, "\nHigh:", temp_high.text, "Low:", temp_low.text + "\n" + precip.text)
我有几个area_Codes,例如:351967899766
,123
,456
我在area_codes之间循环并与手机比较,当我有一个匹配(按照351这样的字符序列)时,它发送一条消息并停止寻找匹配。
你有任何想法如何做这个正则表达式?
答案 0 :(得分:1)
这是您正在寻找的答案吗?迭代区号并查找是否使用迭代区号启动了电话号码。
final String phone = "351967899766";
for (String areaCode : Arrays.asList("123", "456", "351")) {
if (phone.startsWith(areaCode)) {
System.out.println("match");
break;
}
}