You can use
text = text.replace(/(?<=[)[a-z](?=[^][]*])/g, (x) => x.toLocaleUpperCase())
// OR
text = text.replace(/(?<=[)p{Ll}(?=[^][]*])/gu, (x) => x.toLocaleUpperCase())
See the regex demo/regex demo #2. Details:
(?<=[)
- a positive lookbehind that matches a location that is immediately preceded with a [
char
[a-z]
- a lowercase ASCII letter
p{Ll}
- any Unicode lowercase letter
(?=[^][]*])
- a positive lookahead that requires any zero or more chars other than [
and ]
and then a ]
immediately to the right of the current location.
See the JavaScript demo:
const text = 'This [forest or jungle] is [really] beautiful';
console.log( text.replace(/(?<=[)[a-z](?=[^][]*])/g, (x) => x.toLocaleUpperCase()) )
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…