Re: OT: grep and regex patterns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 14, 2016 at 04:02:02PM +1000, cs@xxxxxxxxxx wrote:
> On 13Jul2016 22:03, Mike Wright <nobody@xxxxxxxxxxxxxxxxxxxx> wrote:
> > OK, thanks everybody.
> > 
> > Had to use egrep. This works:
> > 
> > PATTERN='https?://[^/]*\.in(/.*)*'
> > egrep $PATTERN file.of.links > links.in
> 
> You need quotes around $PATTERN when you use it, thus:
> 
>  egrep "$PATTERN" file.of.links > links.in
> 
...
> > Covers cases with https and where nothing follows the .in
> 
> Your:
> 
>  (/.*)*
> 
> is better written:
> 
>  (/.*)?
> 
I'll mention one of my pet peeves (kinda like RLS's UUOC* award).

In a simple pattern matching grep RE, a repetition operator, '*'
(and in egrep '?'), is useless at the start or end of the pattern
and may reduce grep's efficiency.

  grep .*abc
  grep   abc.*
  grep .*abc.*
  grep   abc

Will all match the same set of lines.

Note, I'm not referring to some situations where anchors are used
(ex. 'abc[0-9]*$'), or sed substitutions, or even grep with the
'-o' option to output the matched portion.

Jon

 * Randal L Schwarz' Useless Use Of Cat
-- 
Jon H. LaBadie                  jonfu@xxxxxxxxxx
--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://lists.fedoraproject.org/admin/lists/users@xxxxxxxxxxxxxxxxxxxxxxx
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux