The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
regex question xiamin Shell Programming and Scripting 3 03-05-2009 02:53 AM
Quick regex question retrovertigo Shell Programming and Scripting 1 07-06-2007 05:49 PM
regex question arushunter Shell Programming and Scripting 8 01-04-2007 05:49 PM
Newbie Regex Question ciremg01 UNIX for Dummies Questions & Answers 0 11-30-2005 05:30 PM
regex question rocketkids UNIX for Dummies Questions & Answers 6 02-12-2004 05:49 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2006
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
regex question about greediness

Hello guys,

I am learning greediness part of regular express, and read example as this,

To match text wrapped in double quotes in sentence <The name "McDonald's" is said "makudonarudo" in Japanese>

You need use "[^"]*" to avoid greediness, as following

$ sed 's/"[^"]*"/ /g' wk
The name is said in Japanese

I am a little confused on this, as I know, * means match ZERO or more preceding.
so basically although [^"] mean any character except ", with a * it should turn to match ANY character(s), which will unfortunately include " again,

but why the regex works?
  #2 (permalink)  
Old 08-30-2006
fidodido fidodido is offline
Registered User
  
 

Join Date: Dec 2005
Posts: 49
But you just said preceding, meaning it will match any up until it finds a " again . Also, the g there means 'global', so it will replace every occurance of the matching expression.
  #3 (permalink)  
Old 08-30-2006
fedora fedora is offline
Registered User
  
 

Join Date: Jul 2006
Posts: 94
Quote:
Originally Posted by fidodido
But you just said preceding, meaning it will match any up until it finds a " again . Also, the g there means 'global', so it will replace every occurance of the matching expression.

Hmmm, I think I did not express my question clearly, let me clarify.

let's forget about greediness first, my question is about the regular express [^"]*

In the example above, [^"]* are used to match any characters except ", right?

But, I think it is wrong, * means match ZERO or more preceding

So I think [^"]* does no make sense, it can match "

  #4 (permalink)  
Old 08-30-2006
reborg's Avatar
reborg reborg is offline Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,245
Quote:
Originally Posted by fedora
Hmmm, I think I did not express my question clearly, let me clarify.

let's forget about greediness first, my question is about the regular express [^"]*

In the example above, [^"]* are used to match any characters except ", right?

But, I think it is wrong, * means match ZERO or more preceding

So I think [^"]* does no make sense, it can match "

It can't simply because it a char followed by *, will match the longest string possible, in this case everything up to the next ", or put another way...

a regex "[^"]*" would match "" or "some string" but the match terminates as soon as the second " is hit.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0