Search regular expression with search for hex values in files?

Discussion in 'Perl Misc' started by Peter Hanke, Jan 6, 2008.

  1. Peter Hanke

    Peter Hanke Guest

    For a given file aaa.txt I want to check wether it contains a hex value e.g. x'77' (=1 byte)
    BUT not a hex sequence x'8877' (=two bytes). In other words byte value x'77' should exist
    but it must not NOT be preceded by byte value x'88'.

    How can I specify this (pre-)conditions in ONE regular expression and pass it e.g. to grep?

    Peter
     
    Peter Hanke, Jan 6, 2008
    #1
    1. Advertising

  2. Peter Hanke

    Dr.Ruud Guest

    Peter Hanke schreef:

    > For a given file aaa.txt I want to check wether it contains a hex
    > value e.g. x'77' (=1 byte) BUT not a hex sequence x'8877' (=two
    > bytes). In other words byte value x'77' should exist but it must not
    > NOT be preceded by byte value x'88'.
    >
    > How can I specify this (pre-)conditions in ONE regular expression and
    > pass it e.g. to grep?


    Where you say 'hex value' I assume you just mean 'character value'
    (conveniently presented in hexadecimal format).

    m/(?<!\x88)\x77/

    See `perldoc perlre`, look for "look-behind assertion".

    --
    Affijn, Ruud

    "Gewoon is een tijger."
     
    Dr.Ruud, Jan 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,310
  2. aefxx
    Replies:
    1
    Views:
    595
    Virgil Green
    Dec 17, 2004
  3. Replies:
    10
    Views:
    6,229
    Neredbojias
    Aug 19, 2005
  4. Bengt Richter
    Replies:
    6
    Views:
    474
    Juha Autero
    Aug 19, 2003
  5. jack
    Replies:
    4
    Views:
    590
Loading...

Share This Page