#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    71
    Rep Power
    7

    Regular expressions not working for grep??


    Hello guys,

    I'm trying to locate any template files in our file hierarchy that contain specific patterns... I'm familiar with regex... have been using it for a few years now with the assistance of regexr...

    Now when I try using the syntax found on the man pages and many other how-to sites I never get any results, yet I know there are files with these patterns in them...

    What the deal, yo?

    Examples of patterns I'm using that simply do not return any results:

    grep -r "radius\(" *
    grep -r "maximum\-scale\=1" *
    grep -r "\d+em\;" *


    Any help provided on this matter is greatly appreciated.

    Cheers,
    S
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    71
    Rep Power
    7
    So... the man page says to use backslashes to escape these characters... yet people are telling me that is the opposite of what I should be doing...

    HOWEVER, this is the story since those updates:

    Hmmm isn't this example:

    grep -r 'radius(' *

    the exact opposite of what the man page says below?
    In basic regular expressions the meta-characters ?, +, {, |, (, and ) lose their special meaning; instead use the backslashed versions \?, \+, \{, \|, \(, and \).

    I did read the man page before posting here btw... it doesn't seem to make any sense.

    When I try with the backslash in front of the parenthesis this is the return:

    $ grep -r 'radius\(' *
    grep: Unmatched ( or \(
    I am at the root where many files have multiple lines of CSS3 border-radius styles containing the exact spelling and capitalization as: "-radius(" -In fact I can look them up and open them in the folder tree using vi or nano... however this returns 0 results:

    $ grep -r 'radius(' *
  4. #3
  5. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,897
    Rep Power
    3886
    You're misreading the man-page, though it might be clearer with an example.

    In basic regexps (i.e. if you don't use the -e flag), they lose the special meanings that they normally have when used in regular expressions (i.e. they match the literal characters). Putting a backslash before a '(' character in basic mode turns it into a regular expression meta-character so the regexp engine expects that group to be closed with a corresponding '\)'. The is the opposite behaviour that you'd expect if you're used to PCREs.

    Comments on this post

    • codergeek42 agrees

IMN logo majestic logo threadwatch logo seochat tools logo