1

I have tried separating the wowza logs using regex for data analysis, but I couldn't separate the section below.

I need a SINGLE regex pattern that would satisfy below both log formats.

Format 1:

live wowz://test1.example.com:443/live/_definst_/demo01|wowz://test2.example.com:443/live/_definst_/demo01 test

Format 2:

live demo01 test

I am trying to split the line on the 3 parameters and capturing them in the groups app, streamname and id, but streamname should only capture the text after the last /.

This is what I've tried:

(?<stream_name>[^/]+)$ --> Using this pattern I could only separate the format 1 "wowz" section. Not entire Format 1 example mentioned above.

Expected Output

{

"app": [
    [
        "live"
    ]
],
"streamname": [
    [
        "demo1"
    ]
],
"id": [
    [
        "test"
    ]
]

}

7
  • Can you elaborate on what lines it should match? i.e: why not any line starting with live? Or why would you use [^/]+ to match a line that actually has slashes? Commented Nov 20, 2015 at 14:35
  • @maraiano , I need to split "demo1" from both format logs using single regular expression. expected output: { "app": [ [ "live" ] ], "streamname": [ [ "demo1" ] ], "id": [ [ "test" ] ] } Commented Nov 20, 2015 at 14:47
  • 1
    Try ^(?<app>\S+) (?:\S*/)?(?<streamname>\S+) (?<id>\S+)$ ... Or edit your question showing the relevant part of your log and expected output in the body of your post Commented Nov 20, 2015 at 14:57
  • Still not clear what has to be separed from what. "demo1" means and alfanumeric id of any length? Expand the question please Commented Nov 20, 2015 at 15:07
  • @maraino, Solution works for me. If you post the same in solution tag, I will mark it as Correct answer Commented Nov 20, 2015 at 15:15

1 Answer 1

2

You can achieve what you specified using the following regex:

^(?<app>\S+) (?:\S*/)?(?<streamname>\S+) (?<id>\S+)$

regex101 demo


  • \S+ matches any number of characters except whitespace.

  • (?:\S*/)? to optionally consume the characters in the second parameter up to the last /. This is not included in the group, so it won't be captured.

Sign up to request clarification or add additional context in comments.

3 Comments

thanks, Its solved my Problem. I marked it as Correct Answer
Could you please share some link to learn regex pattern ?. Thanks once again for your kindly help
regular-expressions.info/tutorialcnt.html This is the best IMO. It may take some time reading it, but that's the time you need so you can learn regex

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.