1

Names for Example: note there is no spaces.

JohnJSmith

MikeLJohnson

PeterWWalker

result should be:

JohnSmith

MikeJohnson

PeterWalker

[A-Z]{2} RegEx matches only two cap letters, not sure how to proceed from here.

Thankyou.

1
  • 3
    What happens with "ConanOBrien"?
    – VLAZ
    Commented Apr 24, 2020 at 5:33

1 Answer 1

0

Assuming,you have

1)Name starting with capital Letter followed by some small letters -> [A-Z][a-z]*

2)Capital Middle Letter-> [A-Z]

3)Capital Last Letter followed by some small letters -> [A-Z][a-z]*

U can split them into 3 groups

(^[A-Z][a-z]*)([A-Z])([A-Z][a-z]*)

Since you need first and last group.You can get like this -> $1$3

Eg.

'JohnJSmith'.replace(/(^[A-Z][a-z]*)([A-Z])([A-Z][a-z]*)/,'$1$3')->"JohnSmith"
1
  • Thank you so much.. Works like a charm.. Hopefully it will help other people as well. Your help is appreciated by many. Thanks again.
    – PaulP
    Commented Apr 25, 2020 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.