【发布时间】:2009-06-17 07:25:00
【问题描述】:
我终于解析了维基百科的 wiki 文本。我在这里有以下类型的文本:
{{Airport-list|the Solomon Islands}}
* '''AGAF''' (AFT) – [[Afutara Airport]] – [[Afutara]]
* '''AGAR''' (RNA) – [[Ulawa Airport]] – [[Arona]], [[Ulawa Island]]
* '''AGAT''' (ATD) – [[Uru Harbour]] – [[Atoifi]], [[Malaita]]
* '''AGBA''' – [[Barakoma Airport]] – [[Barakoma]]
我需要检索单个数组中以模式开头的所有行
* '''
我认为这里会调用一个正则表达式来订购,但我的正则表达式部分确实搞砸了。
另外,在另一个示例中,我有以下文本:
{{otheruses}}
{{Infobox Settlement
|official_name = Doha
|native_name = {{rtl-lang|ar|الدوحة}} ''ad-Dawḥa''
|image_skyline = Doha Sheraton.jpg
|imagesize =
|image_caption = West Bay at night
|image_map = QA-01.svg
|mapsize = 100px
|map_caption = Location of the municipality of Doha within [[Qatar]].
|pushpin_map =
|pushpin_label_position =
|pushpin_mapsize =
|subdivision_type = [[Countries of the world|Country]]
|subdivision_name = [[Qatar]]
|subdivision_type1 = [[Municipalities of Qatar|Municipality]]
|subdivision_name1 = [[Ad Dawhah]]
|established_title = Established
|established_date = 1850
|area_total_km2 = 132
|area_total_sq_mi = 51
|area_land_km2 =
|area_land_sq_mi =
|area_water_km2 =
|area_water_sq_mi =
|area_water_percent =
|area_urban_km2 =
|area_urban_sq_mi =
|area_metro_km2 =
|area_metro_sq_mi =
|population_as_of = 2004
|population_note =
|population_footnotes = <ref name=poptotal>[http://www.planning.gov.qa/Qatar-Census-2004/Flash/introduction.html Qatar 2004 Census]</ref>
|population_total = 339847
|population_metro = 998651
|population_density_km2 = 2574
|population_density_sq_mi = 6690
|latd=25 |latm=17 | lats=12 |latNS=N
|longd=51|longm=32 | longs=0| longEW=E
|coordinates_display = inline,title
|coordinates_type = type:city_region:QA
|timezone = [[Arab Standard Time|AST]]
|utc_offset = +3
|website =
|footnotes =
}} <!-- Infobox ends -->
'''Doha''' ({{lang-ar|الدوحة}}, ''{{transl|ar|ad-Dawḥa}}'' or ''{{unicode|ad-Dōḥa}}'') is the [[capital city]] of [[Qatar]]. It has a population of 400,051 according to the 2005 census,<ref name="autogenerated1">[http://www.hotelrentalgroup.com/Qatar/Sheraton%20Doha%20Hotel%20&%20Resort.htm Sheraton Doha Hotel & Resort | Hotel discount bookings in Qatar<!-- Bot generated title -->]</ref> and is located in the [[Ad Dawhah]] municipality on the [[Persian Gulf]]. Doha is Qatar's largest city, with over 80% of the nation's population residing in Doha or its surrounding [[suburbs]], and is also the economic center of the country.
It is also the seat of government of Qatar, which is ruled by [[Sheikh Hamad bin Khalifa Al Thani]]–the current ruling Emir of Qatar.
我需要在这里提取信息框。信息框包含并包含第一次出现
之间的所有文本{{Infobox Settlement
并以第一次出现的
结束}} <!-- Infobox ends -->
当谈到正则表达式时,我完全迷失了,我可以在这里使用帮助。我正在使用 PHP。
编辑!帮助!
我已经战斗了 40 个小时,但我无法让愚蠢的正则表达式正常工作:( 到目前为止,我只有这个:
{{信息框[^\b(\r|\n)}}(\r|\n)\b]*[\b(\r|\n)}}(\r|\n)( \r|\n)\b]
但它不起作用我希望它读取 {{infobox 和以 \n}} 结尾之间的所有字符串数据\n
我正在使用 Php,但无法让它工作 :( 它只是返回第一次出现的 }},而忽略了我希望它检索 }} 的事实。在我浪费更多之前请帮助我理智点:'(
【问题讨论】:
-
这里有两个问题?