0

Example string

ffff7cp37wicb5.hui.com /images/xyz.jpg HTTP/1.1 HIT 103.195.71.140 image/jpeg "trace-id=3948b327-87d5-a6a0-15e5-3e20ef6d6333;parent-id=540089004159950400;span-id=540089004159950400" ^curl mozilla; haa/7.79.1^ ^max-age=2592000^ 0 NOT_DEFINED

I need to match all spaces except the ones that lie between two carets (^) so that I can split the above line into tokens

Tried the solution from here using:

arr = str.split(/\s(?![^^]*\^)/g)

Expectation

ffff7cp37wicb5.hui.com 
/images/xyz.jpg 
HTTP/1.1 
HIT 
103.195.71.140 
image/jpeg 
"trace-id=3948b327-87d5-a6a0-15e5-3e20ef6d6333;parent-id=540089004159950400;span-id=540089004159950400" 
^curl mozilla; haa/7.79.1^ 
^max-age=2592000^ 
0 
NOT_DEFINED

Actual

ffff7cp37wicb5.hui.com /images/xyz.jpg HTTP/1.1 HIT 103.195.71.140 image/jpeg "trace-id=3948b327-87d5-a6a0-15e5-3e20ef6d6333;parent-id=540089004159950400;span-id=540089004159950400" ^curl mozilla; haa/7.79.1^ ^max-age=2592000^
0
NOT_DEFINED
Akash
  • 11
  • 4
  • 2
    Can you [edit] the question to include a few more details: 1) What programming language or tool do you need this for? (Some features aren't available in all regex engines.) 2) What are the exact matches you need for the provided sample (a full example is less ambiguous than a description)? 3) Ideally, can you give your required and current output in some kind of text, rather than an image - perhaps a [mre] of some code using the regex in the language you're working in? – IMSoP Dec 12 '22 at 17:09
  • Please [don’t post images of code, error messages, or other textual data.](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors) – tripleee Dec 12 '22 at 17:14
  • I am unable to think of a way to highlight the spaces that need to be matched. Hence, I have added photos. – Akash Dec 12 '22 at 17:21
  • Please mention tool/lang as @IMSoP already asked for. An efficient way would be to [skip `^`...`^`-parts](https://regex101.com/r/YK0WYL/1) whichs requires PCRE (e.g. PHP, Notepad++). – bobble bubble Dec 12 '22 at 17:39
  • Does this answer your question? [A regex to match a comma that isn't surrounded by quotes](https://stackoverflow.com/questions/2700953/a-regex-to-match-a-comma-that-isnt-surrounded-by-quotes) (Just substitute `^` for `"` and space for `,` I guess) – IMSoP Dec 12 '22 at 17:44
  • Yes, it does. Thanks @IMSoP for the lead. – Akash Dec 12 '22 at 18:08

0 Answers0