2017-01-26 4 views
0

Ich habe ein bisschen Mühe, einen Python-Regex zu funktionieren, wenn es mit Text, der mehrere Zeilen umfasst, übereinstimmt. Mein Beispiel ist:Python regulärer Ausdruck entspricht einem mehrzeiligen JavaScript-Code

function initialize() 
{ 
    var myLatlng = new google.maps.LatLng(23.800567,5.942068); 
    var myOptions = 
    { 
     panControl: true, 
     zoomControl: true, 
     scaleControl: false, 
     streetViewControl: true, 
     zoom: 11, 
     center: myLatlng, 
     mapTypeId: google.maps.MapTypeId.HYBRID 
    } 
    var map = new google.maps.Map(document.getElementById("map"), myOptions); 
    var bounds = new google.maps.LatLngBounds(); 

    var locations = [ 

    ['<div CLASS="Tekst"><B>tss&nbsp;fsdf<\/B><BR>hopp <BR><\/div>', 54.538665,24.885818, 1, 'text'] 
    , 
    ['<div CLASS="Tekst"><\/div>', 24.465462,24.966919, 1, 'text'] 
    ] 

Was ich extrahieren möchte, ist Kontext in Standorten. Als Ergebnis will ich aussehen:

- '<div CLASS="Tekst"><B>tss&nbsp;fsdf<\/B><BR>hopp <BR><\/div>', 
    54.538665,24.885818, 1, 'text' 
- '<div CLASS="Tekst"><\/div>', 24.465462,24.966919, 1, 'text' 

Ich versuche Regex wie folgt aus:

regex = r"var locations =\[\[(.+?)\]\]" 

Aber es funktioniert nicht.

+0

haben Sie versucht, 're.MULTILINE' oder' re.DOTALL'? –

+0

yap. Wahrscheinlich stimmt etwas mit Regex nicht. – user3568005

Antwort

0

hallo Sie können versuchen, diese Regex

re.findall("(<div.+)\]",toparse) 
+0

Danke :) Du rettest mein Leben. Ich verbringe 3 Stunden damit, diesen Regex zu machen: D – user3568005