0

I'm trying to get the first letter of every new word in the following string.

hello_world! hello___America! software-developer **for_life!?**

I've put together the following regex that almost gets there:

(\b\w|(?=)_[^_])

The problem is that it also copies the underscore preceding the next word.

See screenshot: enter image description here

I want the letter after the underscore (or chain of underscores), plus the first letter of all of the other words that I already have highlighted with that regex pattern.

The answer I'm looking for should be abstract enough to capture letters/numbers/words split between one or more underscores.

Here's the Rubular shortlink

1 Answer 1

3

You may perhaps use a positive look-behind assertion ...

\b\w|(?<=_)[^_]
     ^^^^^^

see demo on rubular

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.