9

I want to replace for example F(G(X,Y)); with H(X,Y); In RAD Studio IDE.

The regex I use is:

Find Expression: F\(G\((.+)\)\); Replace Expression: H($1)

The result is not as I expect:

Result: H($1)

It seems the RAD Studio does not recognize the $1 as the contents between two parentheses.
Anybody have an idea?
Thanks

5
  • 2
    Did you read the docs? They will tell you the correct syntax. Commented Dec 10, 2013 at 8:44
  • Yes, I have read the docs, and found nothing in this case. Commented Dec 10, 2013 at 10:22
  • 1
    You didn't look hard enough. It's here: docwiki.embarcadero.com/RADStudio/en/Regular_Expressions From the IDE you can just press F1 in the replace dialog! Trying to guess regex syntax without reading the docs is pointless. Commented Dec 10, 2013 at 10:24
  • I have seen this link, as you see there is nothing about how to replace the group, Not $1 nor \1 will help. see my below comment. Commented Dec 10, 2013 at 10:29
  • 3
    No, it's right there in the link. You just have to read it all carefully. Braces group characters or expressions. Groups can be nested, with a maximum number of 10 groups in a single pattern. For the Replace operation, groups are referred to by a backslash and a number, according to the position in the "Text to find" expression, beginning with 0. For example, given the text to find and replacement strings, Find: {[0-9]}{[a-c]*}, Replace: NUM\1, the string 3abcabc is changed to NUMabcabc. Commented Dec 10, 2013 at 10:31

1 Answer 1

17

Use {} to group the expression rather than () and \1 in the replacement text:

Find Expression: F\(G\({.+}\)\); Replace Expression: H(\0)

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, the "H(\1)" should become "H(\0)" (Zero base)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.