BBEdit text filter - increment value by one


/ Published in: Perl
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.