开发者

Use regex backreference in calculation(Java,Netbeans and not only)

开发者 https://www.devze.com 2022-12-28 16:22 出处:网络
In Netbeans the \"Replace command\"(ctrl+H) has a regular expression checkbox so that i can search and replace in开发者_StackOverflow中文版 the document using regex\'s.

In Netbeans the "Replace command"(ctrl+H) has a regular expression checkbox so that i can search and replace in开发者_StackOverflow中文版 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


Simple answer: no, that's not possible.


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'

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号