-3
I’m not able to separate words this way: In case I have CPFConsole
, wanted to separate to cpf and console.
The code I have separates so:
([A-Z][a-z]+)|([a-z]{0,})|([A-Z]{2,})
But that code separates that way: CPFC
and onsele
.
-3
I’m not able to separate words this way: In case I have CPFConsole
, wanted to separate to cpf and console.
The code I have separates so:
([A-Z][a-z]+)|([a-z]{0,})|([A-Z]{2,})
But that code separates that way: CPFC
and onsele
.
5
If the entrance is CPFConsole
and you want just CPF, you can use that expression:
(^[a-zA-Z]{3})+
This expression takes the first three letters of your word.
See working on Onlineregex.
Edit: According to your comment, if I understood correctly, the expression Juniornunes put works:
^([A-Z]+)([A-Z]{1}[a-z]+)
See on Onlineregex.
So, but it wouldn’t just be to get the number, it would be one of the test cases. It would have to pass in "ambientRG10", and leave each word separate, that regex I got, now when I have an equal word mentioned above "Cpfconsole", the idea in this case would only be to separate a group of capital letters up to the penultimate letter, before they become minute, I do not know if it was clear, this way he would separate (CPF, Console) and return me the two, the same is valid for a case like: "Rgcasa", would have to separate RG and Casa.
@Joseaguiar, these details must be given before you have an answer, precisely to avoid answers that will not help you. When you ask a question ask all relevant information.
@Taisbevalle you are correct in your comment, but it should also be noted that if there is any doubt, it is necessary to question the OP in the comments before answering, to avoid this kind of situation too, so that after the question is clear enough to get an answer, this be answered :)
But from what he explained now in the comment this answer is a solution to his problem!
Thank you very much!!
@Joseaguiar do not forget to mark the answer as a solution (on the left side of this post) so that other people are helped as well!
3
Following the criteria we can set up the REGEX like this:
pattern : /([A-Za-z])([A-Z][a-z])/g
replace : $1 $2
See working on REGEX101.
([A-Za-z])
- Group 1, search 1 capital letter or minuscule.([A-Z][a-z])
- Group 2, search 1 uppercase letter, followed by 1 minuscule letter.Simplified and improved, great example of regex101 +1
Thank you very much!!
Browser other questions tagged java string regex
You are not signed in. Login or sign up in order to post.
What is the criterion for separating words?
– Sorack
See if that helps you:
^([A-Z]+)([A-Z]{1}[a-z]+)
– JuniorNunes
Please post examples of how the original string looks and how you want it to look.
– Calebe Oliveira
@Juniornunes your issue was rejected because you tried to add information that was not authored by the author of the post, and this is not allowed. Always choose to question the comments and instruct the author to make the edit, when additional information is required.
– user28595
@diegofm http://answall.com/questions/170053/como-ficaria-regex-para-tratar-esse-caso?noredirect=1#comment350469_170055
– JuniorNunes
@Juniornunes even so, the correct is to always instruct the author to edit and add, because in the queue you can’t read all the comments that are in the question and the answer, and this type of edition is usually always rejected.
– user28595