You can use a single regular expression, with capture groups:
In [1]: import re
In [2]: path = r'P:\foo\bar\biz\scene\ch01\seq001\s0090\anim\foo\bar\biz'
In [3]: match = re.search(r'(ch\d{2})\\(seq\d{3})\\(s\d{4})', path)
In [4]: if match:
...: print match.groups()
...:
('ch01', 'seq001', 's0090')
In [5]: match.group(1)
Out[5]: 'ch01'
In [6]: match.group(2)
Out[6]: 'seq001'
In [7]: match.group(3)
Out[7]: 's0090'
In [8]: match = re.search(r'ch(\d{2})\\seq(\d{3})\\s(\d{4})', path)
In [9]: print match.groups()
('01', '001', '0090')
On Oct 1, 2013, at 11:06 PM, Panupat Chongstitwattana wrote:
> Hi.
>
> I have this string
>
> path = r'P:\<various directories>\scene\ch01\seq001\s0090\anim\.......'
>
> I want to split out the ch01, seq001 and s0090 into 3 variables (or a list).
> Is there a way to do this with regex in a single line? Maybe with
> re.split(...)
>
> Currently I do it in 3 different steps
>
> find = re.findall(r'ch\d\d', path)
> if find: ch = find[0]
>
> find = re.findall(r'seq\d\d', path)
> if find: seq = find[0]
>
> etc.
>
> Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Python Programming for Autodesk Maya" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.