LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 09:48 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,058

Rep: Reputation: 78
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 09:51 AM.
 
Old 04-11-2017, 10:10 AM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,362

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 09:33 PM
Lazy to revise for exam ghantauke General 10 05-06-2011 11:02 PM
[SOLVED] sed and lazy regex CartmanYO Programming 9 10-06-2010 07:46 AM
XFS Lazy Count? CoderMan Linux - Server 1 03-24-2010 09:17 PM
I know I am lazy but... Vlad_M Linux - General 6 09-24-2002 05:47 PM

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

All times are GMT -5. The time now is 11:08 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration