Regular Expressions

Regular Expressions

Post by Jeem » Tue, 16 Sep 2003 23:41:07



when grepping will this expression math anything?

grep '*U" thefile

It dosen't seem to. It says Match zero or more of nothing and then a U.
Am I missing something?
Thanks
Jeem

 
 
 

Regular Expressions

Post by Andreas Kahar » Tue, 16 Sep 2003 23:48:58



> when grepping will this expression math anything?

> grep '*U" thefile

> It dosen't seem to. It says Match zero or more of nothing and then a U.
> Am I missing something?

You have it back to front:

    grep 'U*' thefile

That will match any line that contains zero or more U's.

Don't be surprised when you find that it matches every single
line in the file.  Every line will contain at least zero U's.

--
Andreas K?h?ri

 
 
 

Regular Expressions

Post by Ed Morto » Wed, 17 Sep 2003 00:06:17



> when grepping will this expression math anything?

> grep '*U" thefile

You're mixing quotation marks - pick either single-tick, ', or
double-tick, ", for both ends of the RE.

Quote:> It dosen't seem to. It says Match zero or more of nothing and then a U.
> Am I missing something?
> Thanks
> Jeem

Pick either type of quotation mark and it'll match a sequence of zero or
more spaces followed by a U. You'd get the same effect with just

        grep 'U'.

Regards,

        Ed.

 
 
 

Regular Expressions

Post by Damian Ibbotso » Wed, 17 Sep 2003 01:51:33


Originally posted by Ed Morton


> > when grepping will this expression math anything?

> > grep '*U" thefile

> You're mixing quotation marks - pick either single-tick, ', or
> double-tick, ", for both ends of the RE.

> > It dosen't seem to. It says Match zero or more of nothing and
>     then a U.
> > Am I missing something?
> > Thanks
> > Jeem

> Pick either type of quotation mark and it'll match a sequence
> of zero or
> more spaces followed by a U. You'd get the same effect with just

>       grep 'U'.

Not sure which greps this might apply to but mine will interpret a *
as exactly that at the beginning of the regular expression and
doesn't treat it as a metacharacter.  I can't see any reference to
this in the man page.

e.g.

echo "*U" | grep "*U" # match found

echo "U" | grep "*U" # no match found

--
Posted via http://dbforums.com

 
 
 

Regular Expressions

Post by Andreas Kahar » Wed, 17 Sep 2003 02:18:00


[cut]

Quote:> Not sure which greps this might apply to but mine will interpret a *
> as exactly that at the beginning of the regular expression and
> doesn't treat it as a metacharacter.  I can't see any reference to
> this in the man page.

> e.g.
> echo "*U" | grep "*U" # match found
> echo "U" | grep "*U" # no match found

You're correct.  The '*' is taken literally (i.e. it has no
special meaning) when in the beginning of a regular expression,
or just after the '^' anchor as in "^*" or "*U" (and in a couple
of other cases).  Hence, "*U" will match the character '*'
followed by the character 'U'.

--
Andreas K?h?ri

 
 
 

Regular Expressions

Post by Ed Morto » Wed, 17 Sep 2003 02:21:56


<snip>

Quote:> Not sure which greps this might apply to but mine will interpret a *
> as exactly that at the beginning of the regular expression and
> doesn't treat it as a metacharacter.  I can't see any reference to
> this in the man page.

<snip>

I thought he had a single blank immediately before the "*" in his RE. It
looked that way in the font I use and his description sounded like he
was trying to describe the effect that would have. Looking at it again,
I see there was no blank so my description was wrong. Thanks for
catching it.

        Ed.

 
 
 

Regular Expressions

Post by Andreas Kahar » Wed, 17 Sep 2003 04:16:14





>> when grepping will this expression math anything?

>> grep '*U" thefile

>> It dosen't seem to. It says Match zero or more of nothing and then a U.
>> Am I missing something?

> You have it back to front:

>     grep 'U*' thefile

> That will match any line that contains zero or more U's.

Ah, I think I know what it is you're trying to do now...  Sorry
for the confusion.  You're trying to match a word that begins
with 'U', don't you?

In that case, try one of these:

    grep '\<U' thefile
    grep '\bU' thefile

This requires GNU grep, which extends the POSIX definition of
the utility.

Does anyone know what the difference between \b and \< is?  It's
not entierly clear from the GNU grep manual I think.

--
Andreas K?h?ri

 
 
 

Regular Expressions

Post by Kevin Rodger » Wed, 17 Sep 2003 05:04:15



> when grepping will this expression math anything?

> grep '*U" thefile

> It dosen't seem to. It says Match zero or more of nothing and then a U.
> Am I missing something?

You are confusing file name patterns expanded by the shell with regular

expressions matched by grep and other text utilities.  They are not the
same.

--
Kevin Rodgers

 
 
 

1. regular expressions

Hi all
I'm not sure if this is particularly unix.programmer related but I'm trying to use it under unix.
I'm trying to do a regular expression search in c using the regex.h library.
 I think I need to use the re_search function but I'm not sure how to actually
go about it.
Can anyone give mee an example of a working function that uses the re_search
 function?

If I should post this on another newsgroup, please let me know.

Regards Nick

2. IPSec NAT Routing etc.

3. regular expression library calls caused core-dumped

4. Comparisons, pricing on network file servers

5. regular expression

6. trouble with interlaced modes

7. regular expression in C programming

8. ATI - ALL-in-WONDER

9. regular expressions

10. Regular expression matching in sh

11. Regular Expression Syntax Limitation?

12. Why there isn't negation operator for regular expression ?

13. perl regular expression