8

I am trying to use the regular expression feature from TexStudio but somehow I can't get it to work and i couldn't find an example or an explanation in the manual.

I am trying to replace variables y1,y2,y3 (y1) with x_1,x_2,x_3 (x_1). In the tip from 'Reg' it is mentioned that 'You can use \1 to \9 in the replace text to insert a submatch.'

enter image description here

I tried to Replace it like this but now everything is replaced with (x_\1) and not the corresponding number. What am I doing wrong?

In adddition: is there a regular expression for all numbers? (1 as well as 1999) For letters there is [A-Z], but [0-9999] only gets the first digit marked.

Thank You!

1 Answer 1

11

You need to use capture groups in order for the \1 to work.

Find: y(\d+)
Replace: x_\1

should work. You can check what is being replaced with the little preview text after the \1 button.

Also, \d characters are digits, then + just means 1 or more.

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .