Loading ...
Sorry, an error occurred while loading the content.

Re: Finding a pattern and extracting preceeding characters

Expand Messages
  • b_harnish
    ... say qwerty , ... has caused ... # To match from a scalar (returns 1-13 chars): $input = Some string here qwerty to match things in. ; ($output) = ($input
    Message 1 of 4 , Apr 26, 2002
    • 0 Attachment
      --- In perl-beginner@y..., "Evan Dembskey" <evan@t...> wrote:
      > Hi,
      >
      >
      > I want to search a $scalar or a file for a particular pattern,
      say "qwerty",
      > and then copy the preceeding 13 characters to another $scalar.
      >
      > I have look at using regexps, but my limited knowledge of them
      has caused
      > this not to bear fruit (if, indeed, this is the way).
      >
      > Could anyone shed some light on this? How do I do it?
      >
      >
      > Regards,
      >
      > Evan

      # To match from a scalar (returns 1-13 chars):
      $input = 'Some string here qwerty to match things in.';
      ($output) = ($input =~ /(.{1,13})qwerty/);

      To match from a file, do the same thing for each line in the file.

      - Brian
    Your message has been successfully submitted and would be delivered to recipients shortly.