I want to parse the result of a grep command in a browser.
Something like grep -nriI "hello" myFolder
The result is a multiline string:
/home/user/folder/file1:1:hello world /home/user/folder/file2:1:world hello /home/user/folder/folder/file3:1:bonjour=hello
First I split the lines to have an array. And parse it with this regex: /^(.*?)\:(\d*)\:(.*?)$/
I have some problems.
- Parse will not work for result with funny char like double point (:)
- When I grep a file, I do not get
pah:line number:contentbut onlyline number:contentso it make the regex more complicated (there is no named group in javascript regex).
Has someone already a good parser or a project which parse it. It has to work in a browser…
I will make a jsfiddle.
My grep (on Ubuntu Linux) has some options that could help, though neither of them are POSIX standard.
For ambiguous output:
For the missing filename:
So use
grep -nriIHZand update your regex to something like this (untested):