Issue
I am dealing with a function that returns variable names with no space between them. Do you have any suggestions for fixing the issue, for example using regex?
Example output: JS876383JS782221JS7721740
, whose component should be separated into something like [JS876383, JS782221 JS7721740
].
Solution
re.split(r"(?<=\d)(?=[A-Za-z])", "JS876383JS782221JS7721740")
# ['JS876383', 'JS782221', 'JS7721740']
The (?<=\d)
is a lookbehind for any digit, and the (?=[A-Za-z])
lookaheads to any letter.
Answered By - Eric Jin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.