ENH: added regex argument to Series.str.split
- [X] closes #43563 
- [X] closes #32835
- [X] closes #25549
- [X] xref #37963 
- [X] tests added / passed
- [X] Ensure all linting tests pass, see [here](https://pandas.pydata.org/pandas-docs/dev/development/contributing_codebase.html#pre-commit) for how to run them
- [X] whatsnew entry

I've preserved current behavior, in which regex = None. Currently, it handles the pattern as a regex if the length of pattern is not 1. I believe that in the future, this may be worth considering deprecating. 

Hello @saehuihwang! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:







There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-11-02 23:23:40 UTC cc @attack68 if any comments lgtm Before merging I think it would be worth just revisiting if we want to get rid of the pattern length 1 logic - its pretty ropey, and there is a good opportunity here. > Before merging I think it would be worth just revisiting if we want to get rid of the pattern length 1 logic - its pretty ropey, and there is a good opportunity here.

Yes, once we have a `regex` kwarg, we could add a deprecation since we would have a path for users to change their code, but I don't think it needs to be done in this PR.

Some issues refer to consistency with the `replace` method, but mainly considering `split` here, I would probably like to see...

Firstly, `Series.str.split` to be compatible with Python `str.split`

So that would require that the default is to always treat `sep` as a literal and rename the `n` arg `maxsplit`

Secondly, add the functionality of re.split to the pandas method without affecting the above.

There are two ways to use the split capability of the Python `re` module, `re.split(pattern, string, maxsplit=0, flags=0)` and `Pattern.split(string, maxsplit=0)`

So I am happy that a `regex` kwarg is added (could perhaps be kwarg only) and also that the `sep` argument can now accept a compiled regex.

By accepting a compiled regex we are now implicitly adding the `case` and `flags` capability in this PR. 

Adding `flags` kwarg (in a follow-up) would make pandas `split` with `regex=True` and a string passed to `sep` consistent with Python `re.split(pattern, string, maxsplit=0, flags=0)`

And also adding a `case` kwarg as a special case of `flags` would make this consistent with pandas `replace`

I think these points are covered by https://github.com/pandas-dev/pandas/pull/44185/files#r739415484 and can be done as a follow-up.

@attack68 anything else preventing merging this

---

Thanks @saehuihwang for the PR. no ,  think thats a great plan and lgtm thanks @saehuihwang very nice.

would like to refactor the inner code if possible to have all of the regex handling in one place if you are interested.