Here are some examples:
Some text ASome text A 8:00-19:008:00-19:00Some text A 8:00-19:00 Some text B
For each case described above, I need to capture (if possible):
- The time (
8:00-19:00) - The beginning (
Some text A) - The end (
Some text B)
With this pattern #^(.*?) ?(\d{1,2}:\d{2}-\d{1,2}:\d{2})?$#, I can capture (from example 2):
Some text A8:00-19:00
But I can’t capture the rest of the line by adding (.*) or (.*?) at the end of the pattern.
Can you help me? Thank you!
I think your main problem is that you’ve made the group of digits optional by adding
?after it (which I don’t think you want).This works for me
/^(.*) ?(\d{1,2}:\d{2}-\d{1,2}:\d{2}) ?(.*)$/: