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 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 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.
haben Sie versucht, 're.MULTILINE' oder' re.DOTALL'? –
yap. Wahrscheinlich stimmt etwas mit Regex nicht. – user3568005