09 September 2009 | |
![]() |
|
3D Dude
Joel Hewitt
Sydney,
Australia
|
Regular Expression named capture group problem
the string i'm trying to match is: "c01_c01_c01dirt"
the regex I am using that works is "([crs][0-9]{2}(dirt)?)_([crs][0-9]{2}(dirt)?)_([crs][0-9]{2}(dirt)?)" to simplify a bit, I use: pat = "([crs][0-9]{2}(dirt)?)" pattern = pat + "_" + pat + "_" + pat I am trying to use a named capture group to achieve the same result. This is what I came up with: "(?<a>([crs][0-9]{2}(dirt)?))(_\k<a>){2}" but for some reason it no longer matches the full string because the optional (dirt)? part seems to be ignored. Any ideas? |
09 September 2009 | |
![]() |
|
Frequenter
Mike Biddlecombe
Animation Programmer
United Front Games
Vancouver,
Canada
|
Maybe something like this?
"([crs][0-9]{2})(_\1){2}dirt"
EDIT: Oops, didn't see that "dirt" suffix was optional Try... "([crs][0-9]{2})(_\1){2}(dirt)?$"
Last edited by biddle : 09 September 2009 at 12:39 AM. |
09 September 2009 | |
![]() |
|
3D Dude
Joel Hewitt
Sydney,
Australia
|
Cheers Mike, works great.
|
09 September 2009 | |
![]() |
|
3D Dude
Joel Hewitt
Sydney,
Australia
|
actually almost as soon as I posted I found out that it doesnt work how I need it to. the dirt part is optional after every c01. so all these would match:
c01_c01_c01 c01dirt_c01_c01 c01_c01_c01dirt c01dirt_c01dirt_c01dirt etc... |
09 September 2009 | |
![]() |
|
Frequenter
Mike Biddlecombe
Animation Programmer
United Front Games
Vancouver,
Canada
|
Try this one:
([crs][0-9]{2})(dirt)?(_\1(dirt)?){2}$
|
09 September 2009 | |
![]() |
|
Expert
|
Thread automatically closed
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities Note that as CGTalk Members, you agree to the terms and conditions of using this website. |
Thread Closed share thread |
«
Previous Thread
|
Next Thread
»
|
|
|