I need to parse xml file and find a values only starts with "123". How i can do this using this code below? It is possible to use regex inside this syntax?
import xml.etree.ElementTree as ET
parse = ET.parse('xml.xml')
print([ events.text for record in parse.findall('.configuration/system/') for events in record.findall('events')])
xml.xml
<rpc-reply>
<configuration>
<system>
<preference>
<events>123</events>
<events>124</events>
<events>1235</events>
</preference>
</system>
</configuration>
</rpc-reply>
re.findall(r'>(123[^<]*)<', xml_string)- gets this:['123', '1235']. Will get anything between>and<that starts with123and consists of any characters that are not<(because it should end the search, obviously).ET.findall. XPath can do such filtering but you need to test what exactly you want. (Just play with it in the interactive console. I do that when I need something specific.)