1

I would like to indent a code string with tabulation. The simple rule is that I must append a tabulation after each line feed inside braces "{}".

My trouble is for nested braces... here I need many tabulation to be exactly the number of nested braces.

Do you think it is possible to do with a regex replace?

1 Answer 1

3

It is impossible with to be done with regex [at least with standard regex, which stand for regular expressions for regular languages] because the language you are describing is irregular!

It is even impossible to know if there are the same number of { as } in a given string with regular language.

We can show that if this language is regular, using homomorphism we can create the language L={anbn} which is a known irregular language.

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

Comments

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.