0

I'm trying to take some text that's in a format where all the spacing, tabs, newlines (control-characters - NPCs) are present. And have it output in a file in Intellij as those control characters would dictate they be formatted.

I may be going about it in a completely daft way. Tell me if I am. What I was trying to do was use the regex replace functionality to select all the control character representations and then replace them with their actual corresponding control characters.

The problem I ran into was I was trying to use regex groups/sets to grab the character and then simply have the replacement be-

\$1

Of course the problem with that is that the slash escapes the dollar sign which I am intending to use to reference the regex group rather than escaping the dollar sign.

I feel like I'm just terribly ignorant of something that should make this far simpler. I'm aware of my ignorance.

Here's my attempts at it so far

regex of -> "\(.)" to select "\n \r or \t"

and my replacement value of

\$1 converts "\n \r or \t" to "$1 $1 or $1"

but if I replace it with

\$1 then "\n \r or \t" remains "\n \r or \t"

I'm at a loss as to how to make the backslash a backslash as it would function if I just did

\n which would convert "\n \r or \t" to

"

or

"

RatavaWen
  • 147
  • 1
  • 8

1 Answers1

0

First try replacing the characters with non-regex input, that way it won't crash the regex. For example, you can search for "(.)" and replace it with 9. Why 9? Because it is not a special regex character. It could be many things besides 9, just not a regex character such as ^[]{}$., etc. Then, you will have "91 91 or 91".

Next, search and replace using regular search/replace, not regex, and replace the 9s with $. Regular search and replace will not recognize $ as the regex end of line character, so you will end up with your desired output: "$1 $1 or $1"

Dharman
  • 30,962
  • 25
  • 85
  • 135