I'm trying to convert studly case/upper case words to snake case, and in most cases the Str::snake($string) helper would work fine, but with strings like FooID, it doesn't turn it into the string I want it to: it converts it to foo_i_d instead of foo_id.
I have a regular expression pattern that works in most cases, but there are few edge cases that I can't quite figure out.
The pattern I have is: /(?=[A-Z].)/
Here is what I'm needing the pattern to match with preg_split:
// Matches correctly
[
'FooBar' => ['Foo', 'Bar'],
'FooID' => ['Foo', 'ID'],
];
// Not correct
[
'FooBARId' => ['Foo', 'B', 'A', 'R', 'Id'], // should be ['Foo', 'BAR', 'Id']
'FooIDS' => ['Foo', 'I', 'DS'], // should be ['Foo', 'IDS']
];
Any help on this would be greatly appreciated.