[%splitstr] Please add regex support as second argument

0 votes
asked Apr 5, 2024 in Wanted features by kasra (1,080 points)

Hi,

It would be great to have regex support.

Like the String.prototype.split() function in js.

It will permit some powerful capabilities, like making easy the creation of a mindmap of a API 

Let's say I want to split a string that is written is PascalCase. With regex thanks to positive lookahead

it's direct : s.split(/(?=[A-Z])/) .

example :  "SomeDumbExemple" 

result : ["Some","Dumb","Exemple"]

Thanks for your feedback 

commented Apr 9, 2024 by The-Lu (83,700 points)

Hello K.,

Good new feature request...

I can propose a PR.

Regards,
Th.

commented Apr 9, 2024 by kasra (1,080 points)
yes please it would be great to have this !

Thanks for your help.

1 Answer

+1 vote
answered Apr 9, 2024 by The-Lu (83,700 points)
selected Apr 9, 2024 by kasra
 
Best answer

Hello K., and all,

It now done with the last snapshot:

We can now use:

%splitstrregex("FooBar", "(?=[A-Z])") -> ["Foo","Bar"]

Enjoy,
Regards,
Th.

commented Apr 10, 2024 by The-Lu (83,700 points)

Hello K., and all,

In fact the name `%splitstrregex` is not so good...sad

As proposed by plantuml, here are some new proposals for change:

  • %split_str_regex
  • %splitstr_regex
  • %split_by_regex
  • %split_regex_separator
  • %split_regex_sep

What is the best for you...? enlightened
Before to change on the main repo.

Regards,
Th.

commented Apr 10, 2024 by kasra (1,080 points)

Consistency is the most important for me.

we already have %splitstr  so maybe %splitstr_regex ?

Thanks for your work !!

commented Apr 12, 2024 by The-Lu (83,700 points)

Considered sold,... cheeky

Therefore it will be %splitstr_regex !

(Available on the last snaphot)

...