Regex to detect patterns that do not start with // or <!--

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Regex to detect patterns that do not start with // or <!--

    Hi,

    I am trying to write a pattern which will give me all matches in java
    files for strings that contain the word "the " but do not start with
    //, <!--.

    This is my pattern so far,

    grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
    'out.print.*?[^\<][^!][^-][^-].*?the'

    It sort of works but I was wondering if anyone has suggestions on how
    to improve it.

    Thanks for any pointers,

    Mike
    Mike Grandmasion Guest

  2. Similar Questions and Discussions

    1. Brush patterns
      I am a fashion illustrator and am drawing very detailed sketches of garments for quality specifications. I have designed a pattern brush to simulate...
    2. HTTP::Proxy - how to detect start and end of URL fetch
      Inside HTTP::Proxy, is there a way to detect (via callback) when the fetch of the URL begins and ends? aTdHvAaNnKcSe
    3. Homemade Patterns
      I want to make my own patterns, which I'd figured out how to do in 4.0, but every since I've used 9.0 I've not had success.
    4. copying patterns
      In illustrator 10, Mac. I have a pattern created by a friend. It was in an 8.5x11" box. I needed the final print to be that size. I also wanted to...
    5. Patterns
      Hi ! I've got a simple looking problem, do maybe someone will have simple, short solution for it. I hava a string whis is an expression e.g.:...
  3. #2

    Default Re: Regex to detect patterns that do not start with // or <!--

    Mike Grandmasion <surfer97301@yahoo.com> wrote:
    > if anyone has suggestions on how
    > to improve it.

    Rewrite it in Perl.


    --
    Tad McClellan SGML consulting
    [email]tadmc@augustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

  4. #3

    Default Re: Regex to detect patterns that do not start with // or <!--

    Mike Grandmasion (surfer97301@yahoo.com) wrote on MMMDCLXIX September
    MCMXCIII in <URL:news:75821f06.0309170822.18e25b5a@posting.goo gle.com>:
    -- Hi,
    --
    -- I am trying to write a pattern which will give me all matches in java
    -- files for strings that contain the word "the " but do not start with
    -- //, <!--.

    m{^(?!//|<!--).*the }

    -- This is my pattern so far,
    --
    -- grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
    -- 'out.print.*?[^\<][^!][^-][^-].*?the'

    $ perl -w
    grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
    String found where operator expected at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
    (Do you need to predeclare PRi?)
    'out.print.*?[^\<][^!][^-][^-].*?the'
    String found where operator expected at - line 2, near "Pi
    'out.print.*?[^\<][^!][^-][^-].*?the'"
    (Missing semicolon on previous line?)
    syntax error at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
    Execution of - aborted due to compilation errors.
    $


    Well, that doesn't compile.

    -- It sort of works but I was wondering if anyone has suggestions on how
    -- to improve it.

    "sort of works"? Is that like "partially pregnant"?


    Abigail
    --
    perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
    Abigail Guest

  5. #4

    Default Re: Regex to detect patterns that do not start with // or <!--

    It is a perl regular expression. That is what the P option
    designates. If I wrote it in perl I would have the exact same
    results.

    [email]tadmc@augustmail.com[/email] (Tad McClellan) wrote in message news:<slrnbmh6n1.82o.tadmc@magna.augustmail.com>.. .
    > Mike Grandmasion <surfer97301@yahoo.com> wrote:
    >
    > > if anyone has suggestions on how
    > > to improve it.
    >
    >
    > Rewrite it in Perl.
    Mike Grandmasion Guest

  6. #5

    Default Re: Regex to detect patterns that do not start with // or <!--

    > m{^(?!//|<!--).*the }

    Yeah I would have though I could negate a grouping like that too but
    if I change my pattern from:

    'out.print.*?[^/][^/].*?the'

    to

    'out.print.*?^(//).*?the'

    I get no output.

    > -- This is my pattern so far,
    > --
    > -- grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
    > -- 'out.print.*?[^\<][^!][^-][^-].*?the'
    >
    > $ perl -w
    > grep -PRi 'out.print.*?[^/][^/].*?the' * | grep -Pi
    > String found where operator expected at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
    > (Do you need to predeclare PRi?)
    > 'out.print.*?[^\<][^!][^-][^-].*?the'
    > String found where operator expected at - line 2, near "Pi
    > 'out.print.*?[^\<][^!][^-][^-].*?the'"
    > (Missing semicolon on previous line?)
    > syntax error at - line 1, near "PRi 'out.print.*?[^/][^/].*?the'"
    > Execution of - aborted due to compilation errors.
    > $
    >
    >
    > Well, that doesn't compile.
    Right it is using a perl regular expression being executed through
    grep on the unix commandline.
    > "sort of works"? Is that like "partially pregnant"?
    No more like thinking you are pregnant with a baby and finding out you
    are pregnant with two. My pattern is returing a little more than I
    want.

    Specifically I get hits on it like this:

    out.print("<!--\r\n\t

    because I assume that the pattern puts the <!-- into the minimal match
    before the ^(<!--) portion.

    Mike
    Mike Grandmasion Guest

  7. #6

    Default Re: Regex to detect patterns that do not start with // or <!--

    Mike Grandmasion (surfer97301@yahoo.com) wrote on MMMDCLXX September
    MCMXCIII in <URL:news:75821f06.0309181001.377b455b@posting.goo gle.com>:
    :) > m{^(?!//|<!--).*the }
    :)
    :) Yeah I would have though I could negate a grouping like that too but
    :) if I change my pattern from:
    :)
    :) 'out.print.*?[^/][^/].*?the'

    What do you think that matches?

    :) to
    :)
    :) 'out.print.*?^(//).*?the'
    :)
    :) I get no output.

    And that surprises you? ^ matches the beginning of the string, so you
    are saying you want to match strings that have something before the
    beginning of the string. I don't think there are many such strings.

    :) > Well, that doesn't compile.
    :)
    :) Right it is using a perl regular expression being executed through
    :) grep on the unix commandline.

    That isn't going to work. You can ask questions about Perl regular
    expressions here, but for grep, there are other places.


    Abigail
    --
    A perl rose: perl -e '@}>-`-,-`-%-'
    Abigail Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139