Putting a character between two other characters?

I need to separate Pascal style identifiers (TheyLookLikeThis) into words separated by an underscore ().
I've tried sed 's/[a-z][A-Z]/&
&/' but this won't work (obviously). I'd love some help.

I have no clue of Pascal - can you please show an example of the desired output?

ThisIsAPascalStyleIdentifier -> This_Is_A_Pascal_Style_Identifier

The problem is that amongst these identifiers are those that already are the correct case, and some of the identifiers have substrings like "OK", "HTTP" etc. which obviously shouldn't be separated. Also, I cannot discard the correct identifiers, since they have to be matched to values in an array. This makes it very tricky for me.

Hope this helps:

echo "ThisIS_PascalID" | sed 's/\([a-z][a-z]*\)\([A-Z]\)/\1_\2/g'

Sample:

$ echo "ThisIS_PascalID" | sed 's/\([a-z][a-z]*\)\([A-Z]\)/\1_\2/g'
This_IS_Pascal_ID

Nice! Thank you!