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 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 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 =\[\[(.+?)\]\]"
但它不工作。
你試過're.MULTILINE'或're.DOTALL'? –
yap。正則表達式可能有些問題。 – user3568005