Jump to content

Recommended Posts

Hello Regexperts,

I have pulled a regex from the internet to seperate words that start with capital letters.  

The regex is here

TEXTJOIN(" ",,REGEXEXTRACT(R158,REGEXREPLACE(R158,"([A-Z][a-z]+)","($1)")))

When I have this: 

HummelfilmTamtam FilmThe Imaginarium Films 

The Regex works and returns this:

Hummelfilm Tamtam Film The Imaginarium Films

But when I have this

Nordisk Film ProductionNadcon FilmZweites Deutsches Fernsehen (ZDF)

or this

Zentropa International SwedenCanal+Ciné+

The Regex breaks.

It looks like the presence of non alphanumeric characters is causing the problem.  Can anyone please help me out and rewrite the Regex so that it works with non alphanumeric characters too?

Edited by MuddyW
Clarity
Link to comment
https://forums.phpfreaks.com/topic/328847-split-words-at-capital-letters/
Share on other sites

  • Barand changed the title to Split words at capital letters

I was following along until the "please do this for me" bit at the end.

REGEXREPLACE + REGEXEXTRACT like that is silly. Not sure where you got it from, but a single REGEXEXTRACT is enough to extract all the <uppercase letter + stuff>s in the cell. Check the documentation/help docs for how to make it match everything instead of just once (which is what it does by default).

For the regex part, it's currently doing <uppercase letter + lowercase letters> so naturally it will only work with lowercase letters and not with numbers or symbols. If you want to match things that look like <uppercase letter + stuff> then realize that "stuff" is a less precise way of saying "keep going until the next uppercase letter". Or in other words, "anything that isn't uppercase". Because computers need you to be precise if you want them to work a certain way. Excel's regex syntax for "anything that isn't ___" is the same as everybody else does it, so you can check either the docs (which I'm sure include a little bit of regular expression syntax) or virtually any other regex resource to find how to write that.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.