سؤال

لقد قمت أخيرًا بتحليل نص ويكيبيديا.لدي النوع التالي من النص هنا:

{{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( | )}}( | )\b]*[\b( | )}}( | )( | )\ب]

لكنه لا يعمل، أريده أن يقرأ جميع بيانات السلسلة بين {{صندوق المعلومات وينتهي بـ }}

أنا أستخدم Php ولا يمكنني تشغيل هذا :( إنه يُرجع فقط التواجد الأول لـ }} متجاهلاً حقيقة أنني أريد استرداده }} مع تغذية الأسطر السابقة.ساعدني من فضلك قبل أن أضيع المزيد من عقلي في هذا :'(

هل كانت مفيدة؟

المحلول

أحتاج إلى استخراج صندوق المعلومات ...

جرب هذا، هذه المرة تأكد من وضع dotall ممكّن:

\{\{Infobox.*?(?=\}\} <!-- Infobox ends -->)


ومرة أخرى توضيح لذلك:

(?xs)    # x=comment mode, s=dotall mode
\{\{     # two opening braces (special char, so needs escaping here.)
Infobox  # literal text
.*?      # any char (including newlines), non-greedily match zero or more times.
(?=      # begin positive lookahead
\}\}     # two closing braces
<!-- Infobox ends --> # literal text
)        # end positive lookahead

سيطابق هذا ما يصل إلى (ولكن باستثناء) تعبير النهاية - يمكنك إزالة المظهر الأمامي نفسه وتضمين المحتويات فقط لجعله يتضمن النهاية، إذا لزم الأمر.

التحديث بناءً على التعليق للإجابة:

\{\{Infobox.*?(?=\n\}\}\n)

كما هو مذكور أعلاه، لكن lookahead يبحث عن قوسين على الخط الخاص بهما.

للسماح بالتعليق اختياريًا أيضًا، استخدم:

\{\{Infobox.*?(?=\n\}\}(?: <!-- Infobox ends-->)?\n)

نصائح أخرى

ميدياويكي مفتوح المصدر. إلقاء نظرة على ...؛ -)

وأعتقد أن أفضل وسيلة لدمج جميع الخطوط في سلسلة واحدة، خاصة بالنسبة لل[إينفوبوإكس.

وبعد ذلك شيئا على غرار

و$ ريج = "\ ن (\ * '' '[^ \ ن] *)"؛

وبالنسبة للجزء الأول (كل شيء بعد خط جديد التي تبدأ مع * '' 'وليس خط جديد).

وبالنسبة للجزء الثاني أنا لا كراس المؤكد الآن، ولكن هذا هو مكان رائع للعب حول قليلا: http://www.solmetra.com/scripts/regex/index.php

وهنا إشارة موجزة عن التعبير اللغوي العادي: http://www.regular-expressions.info/reference.html

<اقتباس فقرة>   

وأحتاج لاسترداد كافة الخطوط في مجموعة واحدة والتي تبدأ مع * ''' نمط

وتمكين وضع متعدد الأسطر وضمان dotall الوضع هو <م> تعطيل ، واستخدام هذا:

^\* '''.*$

و
هذا التعبير تشريح هو:

(?xm-s) # Flags:
        # x enables comment mode (spaces ignore, hashes start comments)
        # m enables multiline mode (^$ match lines)
        # -s disables dotall (. matches newline)
^       # start of line
\*      # literal asterisk
[ ]     # literal space (needs braces in comment mode, but not otherwise)
'''     # three literal apostrophes
.*      # any character (excluding newline), greedily matched zero or many times.
$       # end of line
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top