svent / sift

A fast and powerful alternative to grep
https://sift-tool.org
GNU General Public License v3.0
1.6k stars 108 forks source link

[WORKAROUND] Lookbehind and lookahead possible? #84

Closed sergeevabc closed 7 years ago

sergeevabc commented 7 years ago

I/O

echo Saving to: 'hello.sql' | sift --only-matching (?<=').+(?=')
The filename, directory name, or volume label syntax is incorrect.

Expected

hello.sql

It seems error occurs because cmd.exe fails to process special chars, right?

However the following piece confuses me whether issue is about cmd.exe of Sift itself.

echo Saving to: 'hello.sql' | sift --only-matching -e "(?<=').+(?=')"
Error: cannot parse pattern: error parsing regexp: invalid or unsupported Perl syntax: `(?<`
sergeevabc commented 7 years ago

Err… Hello?

svent commented 7 years ago

You are right, the first example does not work due to escaping problems. The second example is "correct": sift does not support lookbehind/lookahead assertions. The task of extracting the filename is possible though:

echo Saving to: 'hello.sql' | sift "'(.+)'" --replace "$1"
hello.sql
sergeevabc commented 7 years ago

Thank you for a workaround, Sven. Should I rename this issue to “Implement support of lookbehind/lookahead”?

svent commented 7 years ago

That limitation comes from the Go RegEx engine that I use in sift, so unfortunately it cannot easily be fixed.

sergeevabc commented 7 years ago

Oh, it makes life so harder. For example, (\w+)(\.\w+)+(?!.*(\w+)(\.\w+)+) to get a filename from URL does not work. More or less workaround is [^\/?#]*\.[^\/?#]*(\?.*)?(\#.*)?$.