Posted By

page_lab on 05/22/12


Tagged

regex mac perl increment bbedit epub


Versions (?)

BBEdit text filter - increment value by one


 / Published in: Perl
 

URL: http://www.pagelab.com.br

Text filter to increment numbers by one with regex in BBEdit (Mac only)

  1. #!/usr/bin/perl -w
  2.  
  3. # 1. Copy this to a new file in BBEdit (bottom bar of the file window)
  4. # 2. Choose Unix (LF) for line endings
  5. # 3. Save it to ~/Library/Application Support/BBEdit/Text Filters/
  6. # 4. Relaunch BBEdit
  7. # 5. Invoke the script in "Text > apply text filter >" menu
  8. # 6. Presto!
  9.  
  10. while(<>) {
  11. my $line = $_;
  12.  
  13. # If you wish, you can personalize you regex by change the patterns...
  14. # ...between "s/" and "/ge" in the next line.
  15. # The slash in the middle divides the search and replace patterns.
  16. # The "e" part executes the replace as Perl code...
  17. # ...incrementing the value of the former number by one.
  18.  
  19. $line =~ s/(\d+)/($1 + 1)/ge;
  20. print $line;
  21. }

Report this snippet  

You need to login to post a comment.