0

I have such string

Sale: \t\t\t5 Jan \u2013 10 Jan

I want to extract the start and the end of the sale. Very straightforward approach would be to make several spilts, but I want to that using regular expressions. As the result I want to get

start = "5 Jan"
end = "10 Jan"

Is it possible to do that using regex?

3
  • Yes it is. Commented Mar 11, 2018 at 13:15
  • @user202729 thanks, what is the pattern? I'm a bit confused about these unicode symbol Commented Mar 11, 2018 at 13:16
  • Will the start always be the first date and the end always the second date? Commented Mar 11, 2018 at 13:17

2 Answers 2

3

This should help.

import re
s = "Sale: \t\t\t5 Jan \u2013 10 Jan"
f = re.findall(r"\d+ \w{3}", s)
print f

Output:

['5 Jan', '10 Jan']
Sign up to request clarification or add additional context in comments.

Comments

1

This may not be an optimised one but works assuming the string pattern remains the same.

import re
s = 'Sale: \t\t\t5 Jan \u2013 10 Jan'
start, end = re.search(r'Sale:(.*)', s).group(1).strip().replace('\u2013', ',').split(', ')

# start <- 5 Jan
# end <- 10 Jan

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.