我无法找到一个reg-exp在txt文件中找到项目(以粗体斜体标记在下面)


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

您想要一个找到所有它们的正则表达式,还是每个找到一个?您需要返回什么数据(我假设是()和对象名称的内容)?

根据你所拥有的猜测,我假设像这样的东西可以工作:

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

这将匹配前半部分中的一个名称,然后在它之后匹配一个(data)组(您可能希望使其非贪婪)。

如果你用更多的信息编辑问题或评论,我会编辑答案。

@peachykeen:是的,它需要是非贪婪的,否则。*会一直竞争到字符串中的最后一个')'。您还需要匹配组,最好有名称,以便引用您匹配的内容:

/(?P<key>name1|name2|...)(?P<value>(.*?))/

相关内容

  • 没有找到相关文章

最新更新