0

In Netbeans the "Replace command"(ctrl+H) has a regular expression checkbox so that i can search and replace in the document using regex's. Also i can replace using a backreference.

The question is can i use a backreference in a calculation and then use it?

For example with the use of "([0-9]{1})" in the "Find what" i will find all the numbers and with the use of "$1a" in the "replace with" results in replacing all numbers with the number itself followed by the letter a.

123456--->1a2a3a4a5a6a

I want to achive replacing 123456 with 234567 so i want to know if i can use something like ($1 +1) in the "replace with" or if there is another way to do this BUT ONLY with regex(not in MS Excel or anything similar)

Thank you

Argiropoulos Stavros
  • 9,436
  • 11
  • 61
  • 79
  • 1
    That isn't very likely. What would you do with 9, by the way? If this is a one time thing, you can replace `6-->7`, `5-->6`, `4-->5`, etc. Not nice, but you can get it over in a few minutes. – Kobi Apr 28 '10 at 10:05
  • 1
    On a side note, there's never any reason to use the quantifier `{1}` in a regex. Its effect is exactly the same as no quantifier at all, so it's pure clutter. – Alan Moore Apr 28 '10 at 12:29

2 Answers2

2

Simple answer: no, that's not possible.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
0

Notepad++ does this exact thing. I haven't learned how netbeans achieves this.

In Notepad++, you can reference an expression wrapped in () such as your [0-9]{1} in either the current expression again or as a replacement by using \1 for the first () set, \2 for the second and so on.


Example: looking for an RGB value in hex format 0xAA33FF and converting it to the format '#AA33FF' could be done with search expression: 0x([0-9a-fA-F]{6}) and the replace expression: '#\1'