Я не могу найти reg-exp, чтобы найти элементы (отмеченные жирным курсивом ниже) в текстовом файле - PullRequest
0 голосов
/ 06 апреля 2011
------------------------------------------------------------------------------------- Suds ( https://fedorahosted.org/suds/ )  version: 0.3.9 (beta)  build: R658-20100210

Service ( ndfdXML ) tns="http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl" Prefixes (2)
      ns0 = "http://schemas.xmlsoap.org/soap/encoding/"
      ns1 = "http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd" Ports (1):
      (ndfdXMLPort)
         Methods (12):
            ***CornerPoints***(ns1:sectorType sector, )
            ***GmlLatLonList***(ns1:listLatLonType listLatLon, xs:dateTime requestedTime, ns1:featureTypeType featureType, ns1:weatherParametersType weatherParameters, )
            ***GmlTimeSeries***(ns1:listLatLonType listLatLon, xs:dateTime startTime, xs:dateTime endTime, ns1:compTypeType compType, ns1:featureTypeType featureType, xs:string propertyName, )
            ***LatLonListCityNames***(ns1:displayLevelType displayLevel, )
            ***LatLonListLine***(xs:decimal endPoint1Lat, xs:decimal endPoint1Lon, xs:decimal endPoint2Lat, xs:decimal endPoint2Lon, )
            ***LatLonListSquare***(xs:decimal centerPointLat, xs:decimal centerPointLon, xs:decimal distanceLat, xs:decimal distanceLon, xs:decimal resolution, )
            ***LatLonListSubgrid***(xs:decimal lowerLeftLatitude, xs:decimal lowerLeftLongitude, xs:decimal upperRightLatitude, xs:decimal upperRightLongitude, xs:decimal resolution, )
            ***LatLonListZipCode***(ns1:zipCodeListType zipCodeList, )
            **NDFDgen**(xs:decimal latitude, xs:decimal longitude, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters, )
            ***NDFDgenByDay***(xs:decimal latitude, xs:decimal longitude, xs:date startDate, xs:integer numDays, ns1:formatType format, )
            ***NDFDgenByDayLatLonList***(ns1:listLatLonType listLatLon, xs:date startDate, xs:integer numDays, ns1:formatType format, )
            ***NDFDgenLatLonList***(ns1:listLatLonType listLatLon, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters, )
         Types (60):
            ns0:Array
            ns0:ENTITIES
            ns0:ENTITY
            ns0:ID
            ns0:IDREF
            ns0:IDREFS
            ns0:NCName
            ns0:NMTOKEN
            ns0:NMTOKENS
            ns0:NOTATION
            ns0:Name
            ns0:QName
            ns0:Struct
            ns0:anyURI
            ns0:arrayCoordinate
            ns0:base64
            ns0:base64Binary
            ns0:boolean
            ns0:byte
            ns1:compTypeType
            ns0:date
            ns0:dateTime
            ns0:decimal
            ns1:displayLevelType
            ns0:double
            ns0:duration
            ns1:featureTypeType
            ns0:float
            ns1:formatType
            ns0:gDay
            ns0:gMonth
            ns0:gMonthDay
            ns0:gYear
            ns0:gYearMonth
            ns0:hexBinary
            ns0:int
            ns0:integer
            ns0:language
            ns1:latLonPairType
            ns1:listCityNamesType
            ns1:listLatLonType
            ns0:long
            ns0:negativeInteger
            ns0:nonNegativeInteger
            ns0:nonPositiveInteger
            ns0:normalizedString
            ns0:positiveInteger
            ns1:productType
            ns1:sectorType
            ns0:short
            ns0:string
            ns0:time
            ns0:token
            ns0:unsignedByte
            ns0:unsignedInt
            ns0:unsignedLong
            ns0:unsignedShort
            ns1:weatherParametersType
            ns1:zipCodeListType
            ns1:zipCodeType
-------------------------------------------------------------------------------------------

Ответы [ 3 ]

0 голосов
/ 06 апреля 2011
import re
text='''Service ( ndfdXML ) tns="http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl" Prefixes (2) ns0 = "http://schemas.xmlsoap.org/soap/encoding/" ns1 = "http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd" Ports (1): (ndfdXMLPort) Methods (12): CornerPoints(ns1:sectorType sector, ) GmlLatLonList(ns1:listLatLonType listLatLon, xs:dateTime requestedTime, ns1:featureTypeType featureType, ns1:weatherParametersType weatherParameters, ) GmlTimeSeries(ns1:listLatLonType listLatLon, xs:dateTime startTime, xs:dateTime endTime, ns1:compTypeType compType, ns1:featureTypeType featureType, xs:string propertyName, ) LatLonListCityNames(ns1:displayLevelType displayLevel, ) LatLonListLine(xs:decimal endPoint1Lat, xs:decimal endPoint1Lon, xs:decimal endPoint2Lat, xs:decimal endPoint2Lon, ) LatLonListSquare(xs:decimal centerPointLat, xs:decimal centerPointLon, xs:decimal distanceLat, xs:decimal distanceLon, xs:decimal resolution, ) LatLonListSubgrid(xs:decimal lowerLeftLatitude, xs:decimal lowerLeftLongitude, xs:decimal upperRightLatitude, xs:decimal upperRightLongitude, xs:decimal resolution, ) LatLonListZipCode(ns1:zipCodeListType zipCodeList, ) NDFDgen(xs:decimal latitude, xs:decimal longitude, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters, ) NDFDgenByDay(xs:decimal latitude, xs:decimal longitude, xs:date startDate, xs:integer numDays, ns1:formatType format, ) NDFDgenByDayLatLonList(ns1:listLatLonType listLatLon, xs:date startDate, xs:integer numDays, ns1:formatType format, ) NDFDgenLatLonList(ns1:listLatLonType listLatLon, ns1:productType product, xs:dateTime startTime, xs:dateTime endTime, ns1:weatherParametersType weatherParameters, ) Types (60): ns0:Array ns0:ENTITIES ns0:ENTITY ns0:ID ns0:IDREF ns0:IDREFS ns0:NCName ns0:NMTOKEN ns0:NMTOKENS ns0:NOTATION ns0:Name ns0:QName ns0:Struct ns0:anyURI ns0:arrayCoordinate ns0:base64 ns0:base64Binary ns0:boolean ns0:byte ns1:compTypeType ns0:date ns0:dateTime ns0:decimal ns1:displayLevelType ns0:double ns0:duration ns1:featureTypeType ns0:float ns1:formatType ns0:gDay ns0:gMonth ns0:gMonthDay ns0:gYear ns0:gYearMonth ns0:hexBinary ns0:int ns0:integer ns0:language ns1:latLonPairType ns1:listCityNamesType ns1:listLatLonType ns0:long ns0:negativeInteger ns0:nonNegativeInteger ns0:nonPositiveInteger ns0:normalizedString ns0:positiveInteger ns1:productType ns1:sectorType ns0:short ns0:string ns0:time ns0:token ns0:unsignedByte ns0:unsignedInt ns0:unsignedLong ns0:unsignedShort ns1:weatherParametersType ns1:zipCodeListType'''

for match in re.findall(r"[a-zA-Z]+?\s*\([a-z]*?[0-9]*?:",text):
    print match.split("(")[0]
0 голосов
/ 06 апреля 2011

@ peachykeen: да, он должен быть не жадным, в противном случае. * Мчится до самого последнего ')' в строке. Вам также нужны группы совпадений, желательно именованные, чтобы ссылаться на то, что вы сопоставили:

/(?P<key>name1|name2|...)(?P<value>\(.*?\))/
0 голосов
/ 06 апреля 2011

Хотите ли вы регулярное выражение, которое находит их всех или по одному для каждого?Какие данные вам нужны обратно (я предполагаю, что содержимое () и имя объекта)?

Исходя из того, что у вас есть, я предполагаю, что что-то вроде этого может работать:

((CornerPoints|LatLonListZipCode|other|names)\(.*\)))

Тобудет соответствовать одному из имен в первой половине, затем группе (data) после него (возможно, вы захотите сделать его нежадным).

Если вы отредактируете вопрос или комментарий с дополнительной информацией, я 'отредактирую ответ.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...