SORU
6 Kasım 2008, PERŞEMBE


Nasıl bir düzenli ifade ile geçerli Romen rakamları maç mı?

my other problem, ben düşünürken bile Romen rakamları (onları oluşturan bırak, bağlam serbest dilbilgisi) eşleşen bir düzenli ifade oluşturmak mümkün değil karar verdi

Bu sorun, yalnızca geçerli Romen rakamları eşleştirme. , 990 DEĞİLDİR örneğin"","" . CMXC XM

Bunun için düzenli yapmak benim sorunum izin veya bazı karakterler izin vermek için geriye bakmak lazım. Hadi binlerce ve yüzlerce örnek al.

{0,2}M C izin verebilirim?M (900, 1000, 1900,, 2900 2000 ve 3000 için izin vermek için). Eğer maçı CM üzerinde İse, aşağıdaki karakter C veya D zaten 900 olduğum için () izin veremem.

Nasıl bir düzenli ifade bu ifade edebilirim?
Eğer sadece bir düzenli ifade olarak ifade edilebilir değilse, açık kaynak kodlu bir gramer olarak ifade edilebilir mi?

CEVAP
6 Kasım 2008, PERŞEMBE


Deneyin:

^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$

Hadi ağla:


M{0,4}

Bu binlerce bölümü belirtir ve temelde 0 4000 arasında tırmanır. Nispeten basit bir şey

   0: <empty>  matched by M{0}
1000: M        matched by M{1}
2000: MM       matched by M{2}
3000: MMM      matched by M{3}
4000: MMMM     matched by M{4}

(CM|CD|D?C{0,3})

Biraz daha karmaşık, bu yüzlerce bölüm için ve tüm olasılıkları kapsar

  0: <empty>  matched by D?C{0} (with D not there)
100: C        matched by D?C{1} (with D not there)
200: CC       matched by D?C{2} (with D not there)
300: CCC      matched by D?C{3} (with D not there)
400: CD       matched by CD
500: D        matched by D?C{0} (with D there)
600: DC       matched by D?C{1} (with D there)
700: DCC      matched by D?C{2} (with D there)
800: DCCC     matched by D?C{3} (with D there)
900: CM       matched by CM

(XC|XL|L?X{0,3})

Onlarca yer için önceki bölümünde ama aynı kuralları:

 0: <empty>  matched by L?X{0} (with L not there)
10: X        matched by L?X{1} (with L not there)
20: XX       matched by L?X{2} (with L not there)
30: XXX      matched by L?X{3} (with L not there)
40: XL       matched by XL
50: L        matched by L?X{0} (with L there)
60: LX       matched by L?X{1} (with L there)
70: LXX      matched by L?X{2} (with L there)
80: LXXX     matched by L?X{3} (with L there)
90: XC       matched by XC

(IX|IV|V?I{0,3})

Bu birimler bölüm işleme 0 9 da benzer önceki iki bölüm (Romen rakamları, rağmen onların görünüşteki tuhaflık, bazı mantıksal kuralları bir kez seni anlamak ne onlar):

0: <empty>  matched by V?I{0} (with V not there)
1: I        matched by V?I{1} (with V not there)
2: II       matched by V?I{2} (with V not there)
3: III      matched by V?I{3} (with V not there)
4: IV       matched by IV
5: V        matched by V?I{0} (with V there)
6: VI       matched by V?I{1} (with V there)
7: VII      matched by V?I{2} (with V there)
8: VIII     matched by V?I{3} (with V there)
9: IX       matched by IX

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • BASS212M

    BASS212M

    15 Temmuz 2009
  • BlackBoxTV

    BlackBoxTV

    7 Mayıs 2007
  • TheDailyTechDose

    TheDailyTech

    15 EKİM 2012