LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-11-2017, 08:48 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
lazy +?


Hi,

If I write this:
Code:
echo "This is <EM>string</EM>" | grep -E '<.+?>'
I get the folowing highlight:
Code:
This is a <EM>string</EM>
Why is it all highlighted instead of only the occurrences of "<EM>"?

I also tested it on regex sites (regex101.com) and it works fine. Why does grep behave differently?

Last edited by vincix; 04-11-2017 at 08:51 AM.
 
Old 04-11-2017, 09:10 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
It's because grep does not, by default, support lazy regex. You can try using the "-P" (--perl-regexp) option which asks grep to interpret the pattern as a Perl regex. Note that Perl regex is not fully supported in grep.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scheme: Lazy evaluation stateless Programming 5 06-18-2013 08:33 PM
Lazy to revise for exam ghantauke General 10 05-06-2011 10:02 PM
[SOLVED] sed and lazy regex CartmanYO Programming 9 10-06-2010 06:46 AM
XFS Lazy Count? CoderMan Linux - Server 1 03-24-2010 08:17 PM
I know I am lazy but... Vlad_M Linux - General 6 09-24-2002 04:47 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration