-1

I want to define (#define) 10 IR with its respective pin numbers

#define IR1 A1
#define IR2 A2
....
#define IR10 A10

the difference is in only digits, it just incrementing by 1

how to use regex to copy

#define IR1 A1

and paste as

#define IR2 A2

and so on...

and at last, I want to write only one line code and get 9 or more lines of code,

there is no need knowledge of Arduino, just I want to get an incremental copy of

#define IR1 A1
Norman Gray
  • 11,978
  • 2
  • 33
  • 56
  • https://stackoverflow.com/q/12941362 – Dave Newton Aug 11 '19 at 14:26
  • This isn't really a coding question, but an editor or IDE question, and consequently there would be one answer per editor. Most of those answers would be ‘this is hard’. Myself, I'd do this with jot + sed outside the editor if I had 10s of lines to generate, but for fewer than 20–30 lines that would probably be more hassle than copying the line multiple times and tweaking it by hand. You don't have to automate _everything_. – Norman Gray Aug 11 '19 at 14:26
  • In other words: doable? Sort of. Valuable? No: use a real editor you can script, and make it actually useful. – Dave Newton Aug 11 '19 at 14:27
  • @NormanGray IMO regex questions are completely on-topic, and are programming--regex area well-known DSL. Is it a good solution for this problem? No. But on-topic. – Dave Newton Aug 11 '19 at 14:36
  • @DaveNewton Sure, regexes are programming (and that's why I didn't edit away that tag). But this is at heart a ‘how do I use my editor?’ question. – Norman Gray Aug 11 '19 at 14:48
  • @NormanGray It's a "how do i increment a number via regex" question. – Dave Newton Aug 11 '19 at 15:23
  • Its a 1 liner in Perl `$str =~ s/IR(\d+) A(\d+)/IR$1+1 A$2+1/e` basically a replacement callback –  Aug 11 '19 at 17:58

1 Answers1

0

I would do this with a loop in a one-liner use-your-favourite-language script.

For example, in Perl:

perl -e 'for (my $i=0; $i<10; ++$i) { print "#define IR$i A$i\n"; }'

or in bash:

for i in `seq 1 10`; do echo "#define IR$i A$i"; done

To be honest, I see no need to do this in a regex. Just run the above and cut and paste the results into your editor.

joanis
  • 10,635
  • 14
  • 30
  • 40