-1

I have text below and I am matching group 1,2, and 3 in python regex just fine until I want to match 'me' which is between 'srcuser: ' and html line break tag. my regex is seqno: (\d+).+?src: (\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+?dst: (\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+?srcuser: (.+)?[html line break her]

domain: 1<br/>receive_time: 2017/10/25 13:47:19<br/>serial: 00790100000<br/>seqno: 7198725<br/>actionflags: 0x0<br/>type: THREAT<br/>subtype: spyware<br/>config_ver: 1<br/>time_generated: 2017/10/25 13:47:19<br/>src: 1.1.1.1<br/>dst: 2.2.2.2<br/>natsrc: 1.1.1.1<br/>natdst: 2.2.2.2<br/>rule: to INTERNET<br/>srcuser: me<br/>blabla

Please advise

irom
  • 3,316
  • 14
  • 54
  • 86
  • 1
    Why o' why do you people insist on [banging your heads](https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) against the wall? – Nir Alfasi Oct 25 '17 at 18:27
  • If you really, really must do this with regex (you don't), at least do it in multiple steps. – CAustin Oct 25 '17 at 18:32
  • Using regex, although I'd suggest not to, you can use `(?:
    )?\s*(\w+):\s*(.*?(?=\s*
    |$))`. This prevents hardcoding of specific values. Use your code to determine which values you actually require based on group 1's values.
    – ctwheels Oct 25 '17 at 18:38

1 Answers1

0

You may give a try to:

seqno: (\d+).+?src: (\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+?dst: (\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}).+?srcuser: (.+)?<br\/>

Demo

PJProudhon
  • 835
  • 15
  • 17