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

regex or substitution or replace characterized stuff was Can you please help???

Expand Messages
  • Al
    Hi, You mentioned Perl? I m not sure what your question is. 1. Enclosed perl below is close if you not need to go multi or across line(s) with search criteria.
    Message 1 of 4 , Nov 19, 2009
    • 0 Attachment
      Hi,

      You mentioned Perl?

      I'm not sure what your question is.

      1. Enclosed perl below is close if you not need to go multi or across
      line(s) with search criteria.

      2. But if each or any of your search item overlaps line(s) then **the
      enclosed perl below will not work**

      In the case of 2 above, you will need to do a file slurp into a scalar
      variable and then utilize of anti greed operator(s) in the substitution
      and also use the g for global option (# 2 gets more trickier to do than
      # 1 above.)

      s/first/second/g;

      Above shows the g option in use with the substitution operator. Finding
      appropriate anti greed is an exercise that I leave up for grabs.



      #!/usr/bin/perl -w
      use strict;

      my $old = shift;
      my $new = "$old.tmp";
      # my $base_url = ';
      open(OLD, "<", $old) or die "cant open $old: $!";
      open(NEW, ">", $new) or die "cant open $new: $!";
      while (<OLD>) {

      # 1
      # s/<cardset\.*|releasedate\.*|card_count\.*/\n/;

      # or (instead of # 1)

      s/<cardset\.*/\n/;
      s/releasedate\.*/\n/;
      s/card_count\.*/\n/;


      # puts each line, modified or not, into NEW
      print NEW $_;
      }
      # print NEW $htm_tag;
      close(OLD) or die "cant open $old: $!";
      close(NEW) or die "cant close $new: $!";
      rename($old, "$old.orig") or die "cant rename $old to $old.orig: $!";
      rename($new, "$old") or die "cant rename $new to $old: $!";
      # end

      Alan.

      RudiV wrote:
      > < . . . >
      > I had to do the Replace option in 3 steps: as I could not figure out how to embed the CRLF and the end of each line into the find command)
      >
      > 1) Line 2 as: find: <cardset(.*) replace with ABCDEF
      > 2) Line 3 as: find: releasedate(.*) replace with ABCDEF
      > 3) Line 4 as: find card_count(.*) replace with ABCDEF
      > 4) Save as a txt file
      > 5) Use Notepad to find ABCDEF and replace with a blank line.
      >
      > (I could not figure out what character in your software to specify in the replace field for a blank line)
      >
      > What I would have liked to have been able to do was steps 1-3 above in 1 find sequence (syntax?) and then have replace replace the found string with blank lines.
      >
      > Thanks in advance for you assistance!!!
      >
      > Best,
      > Rudi
      >
    • Sheri
      ... Hi Rudi, Using regex in NoteTab s Find and Replace dialog or clipcode, you can match CRLF with R or with r n. Another way is to include linebreak
      Message 2 of 4 , Nov 19, 2009
      • 0 Attachment
        --- In ntb-scripts@yahoogroups.com, "RudiV" <ms65@...> wrote:
        >
        > I had to do the Replace option in 3 steps: as I could not figure
        > out how to embed the CRLF and the end of each line into the find
        > command)
        >
        > 1) Line 2 as: find: <cardset(.*) replace with ABCDEF
        > 2) Line 3 as: find: releasedate(.*) replace with ABCDEF
        > 3) Line 4 as: find card_count(.*) replace with ABCDEF
        > 4) Save as a txt file
        > 5) Use Notepad to find ABCDEF and replace with a blank line.
        >
        > (I could not figure out what character in your software to
        > specify in the replace field for a blank line)

        >
        > What I would have liked to have been able to do was steps 1-3
        > above in 1 find sequence (syntax?) and then have replace replace
        > the found string with blank lines.
        >
        > Thanks in advance for you assistance!!!
        >

        Hi Rudi,

        Using regex in NoteTab's Find and Replace dialog or clipcode, you can match CRLF with \R or with \r\n. Another way is to include linebreak characters in what matches dot, by including (?s) at the beginning of your find pattern.

        You can include a CRLF in replacement text with \r\n

        However, I believe the following would best suit your purposes:

        ^!Replace "^(<cardset|releasedate|card_count).+" >> "" RAWS

        Since the CRLF is not matched, it is still in the file after the replacement. If you want an extra line inserted for each match, it would be:

        ^!Replace "^(<cardset|releasedate|card_count).+" >> "\r\n" RAWS

        There is a detailed, techy regex.chm file in the NoteTab application folder that gives all the details for the PCRE regex engine used in NoteTab. You can access it from the Help menu.

        Regards,
        Sheri
      • Don - HtmlFixIt.com
        Sheri, Now is a good time for us to repeat the helpful links for regex help that you have given before (one is at end of this email). One of them is what
        Message 3 of 4 , Nov 19, 2009
        • 0 Attachment
          Sheri,

          Now is a good time for us to repeat the helpful links for regex help
          that you have given before (one is at end of this email). One of them
          is what finally got me over (or at least on) the hump of understanding.
          It was a helpful tips type of presentation. I converted it from a
          powerpoint to plain text so that I could use it in notetab easier (and
          search it better) and I also now keep a "handyregexbits.txt" file in my
          favorites. It has things like (?s) in it which is the multi-line
          designation.

          I find I use it less and less as I actually now start to understand what
          I am doing and why I am doing it.

          Lastly I would encourage anyone starting with regex to get regex buddy.
          Whenever a pattern I write doesn't match as expected, I use that
          program. I start slowly at the left and move to the right and it shows
          what is matched when you select part of the search term it highlights
          the match in the lower window. Solves many issues.

          Someday I'll tackle look backs and assertions and stuff like that ...
          but for now, I really think I can do some amazing stuff with a good
          regex search term. I still use \r\n just because \R didn't work when I
          started ... I'll try to improve and actually I have used \R a few times
          lately.

          Have a great night everyone.

          Don

          The link:
          http://www.gravitonic.com/talks/
          Andrei’s Regex Clinic
          I note that there are some more recent versions -- I'll have to download
          and see if they have advanced.

          I believe regex discussion is essentially welcome either her or in clips
          list. Is that fair? I have copied both groups.

          >
          > Hi Rudi,
          >
          > Using regex in NoteTab's Find and Replace dialog or clipcode, you can match CRLF with \R or with \r\n. Another way is to include linebreak characters in what matches dot, by including (?s) at the beginning of your find pattern.
          >
          > You can include a CRLF in replacement text with \r\n
          >
          > However, I believe the following would best suit your purposes:
          >
          > ^!Replace "^(<cardset|releasedate|card_count).+" >> "" RAWS
          >
          > Since the CRLF is not matched, it is still in the file after the replacement. If you want an extra line inserted for each match, it would be:
          >
          > ^!Replace "^(<cardset|releasedate|card_count).+" >> "\r\n" RAWS
          >
          > There is a detailed, techy regex.chm file in the NoteTab application folder that gives all the details for the PCRE regex engine used in NoteTab. You can access it from the Help menu.
          >
          > Regards,
          > Sheri
        Your message has been successfully submitted and would be delivered to recipients shortly.