Giter Club home page Giter Club logo

Comments (8)

sshaw avatar sshaw commented on August 18, 2024 1

Working!

Note that $3 does not need to be quoted.

You also can use non-capturing parenthesis around the groups you don't want to capture, then use print $1:

perl -ne '/^Help on (?:.+ in )*(?:module|package) (.*)(?=:$)/ and print $1'

Just an FYI.

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

Or instead of using Perl regexes (-P), just use perl

That's interesting.. didn't think of that.

Also if you use egrep then you don't have to escape any of ()+.

I believe it's more canonical to use grep -E instead of egrep? In any case, I first became a fan of grep -E (and sed -r) and then grep -P.

I'll have to find some time to research replacing the grep -P and sed -r.

Thanks for all that info.

from eless.

sshaw avatar sshaw commented on August 18, 2024

I believe it's more canonical to use grep -E instead of egrep?

Not sure.

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

Note sure

Oh well, from man grep (of course GNU grep):

In addition, two variant programs egrep and fgrep are available. egrep is
the same as grep -E. fgrep is the same as grep -F. Direct invocation as
either egrep or fgrep is deprecated, but is provided to allow historical
applications that rely on them to run unmodified.

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

I'll need to spend some time understanding how to convert grep -Po .. expressions to perl -ne ...

Help me out if you already have the answer :)

> echo "Help on Quitter in module _sitebuiltins object:" | \grep -Po '^Help on (.+ in )*(module|package) \K(.*)(?=:$)'
_sitebuiltins object

> echo "Help on Quitter in module _sitebuiltins object:" | \perl -ne '/^Help on (.+ in )*(module|package) \K(.*)(?=:$)/ and print'
Help on Quitter in module _sitebuiltins object:

Need to figure out out to make perl return only the stuff after \K and before (?= .. ) (that's what the -o in grep does.. and the -P makes it understand \K and look-ahead).

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

OK, this worked:

echo "Help on Quitter in module _sitebuiltins object:" | \perl -ne '/^Help on (.+ in )*(module|package) (.*)(?=:$)/ and print "$3"'

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

Please test the replace-grep-with-perl branch.

from eless.

kaushalmodi avatar kaushalmodi commented on August 18, 2024

Note that $3 does not need to be quoted. You also can use non-capturing parenthesis around the groups you don't want to capture,

Thanks, of course. Completely forgot that elisp regexp is not the only place you could do that :)

from eless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.