2017-01-26 67 views
0

我在Python跨語言匹配跨越多行的文本時遇到了一些麻煩。我的例子是:Python正則表達式匹配多行JavaScript代碼

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'] 
    ] 

我想要提取的是位置上下文。至於結果,我想是這樣的:

- '<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' 

我嘗試正則表達式是這樣的:

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

但它不工作。

+0

你試過're.MULTILINE'或're.DOTALL'? –

+0

yap。正則表達式可能有些問題。 – user3568005

回答

0

你好你可以試試這個正則表達式

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

謝謝:)你救了我的命。我花了3個小時做這個正則表達式:D – user3568005