Answer the question
In order to leave comments, you need to log in
Is it possible (if so, how?) to replace the first lowercase letter of the first word with an uppercase letter via regular expressions in java?
I have several sentences
this text has two sentences. this is the second one. Aggf. fgjdfg dfgjjdf dkkldf. FGjdfgj. lLIFgrkg
Some of them start with a lowercase letter. Is it possible to replace them with capital letters via regular expressions (java) and if so, how?
Capturing the first lowercase letters of the first words ^[az]|(?<=\.\s)[az]
Answer the question
In order to leave comments, you need to log in
It is possible and through regular, it is possible and without regular.
The correct answer is no. The functionality of regular expressions is to find and indicate what is found. You can see how Pattern/Matcher works in pairs. They just find groups of expressions and point the finger, they say, this is where matching came up.
But there is a programming language API such as String::replace which allows using
regular expressions to find-and-replace in a single operation.
But this particular operation - the capitalization of the first letter in a Java string, I would do simply through substring () and toUpper (). It will be hundreds of times faster in time. we will not involve compiling the regex pattern in the process. Roughly speaking, if you decide to shoot at the birds, then take a slingshot. You don't need a gun.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question