I have a working reggae that gives me the results that I want to give, even then it does not require security (stupid Proof)
Let's say I have a reg box that corresponds to some parts of a path: [ Dev / model / props / furniture / couch / data / fbx "regex = re.compile (" (. +) / Dev / model /(.+)/(.+)/ data / FBX ") m = Regex.search (Path) if m: print m.groups () # ('C: / Projects / foo', 'props / furniture', 'couch') ] I want A Any character capable of match up to the following part of the regex will match some or more folders. Let's say that we define a folder for simplicity in terms of words (letter or none) ending with slash:
[ \ W] * / And I want to group zero to ten
I had something in my mind (note that this does not work! ):
# words matches any number of characters that term ends with zero by ten times ([[\ w] * /] {0,10}) # Slash noise Edit Once: ([[\ w] * /]? Edit:
Based on the answer of RedBaron and jamylak I came up with the following: / P>
((?: [: \ W] + /) {0}} This would be a group of three zero events: [w] a With the character ending with 'slash' / '?': In the beginning of the group it is not being sent back from the matching groups. Even then the outer group that connects them, we only get completely grouped results .
One with this Atr issue I want to match that I last part probably a file. (That is why it is not finished with slash.) I also like to get it back without the slash behind the regex, but I can also strip the result end easily.
Any feedback is highly appreciated. If this is the way to go, then I will add it as an answer.
Edit:
It is related:
UPDATE / EDIT: has been given so far Based on all the answers I have come with many efforts, yet they all become very slow at the end. [ Re: Path = "C: / Projects / Foo / Davem / Model / Props / Furniture / Thought / Data / FBX" Reggae = Rie Compile (R "" ((?: ^ (?: [\ W:] + /?) +) | (?: (?:? & Lt; = /) (?: [\ W] + /?) +)) / Dev / model / "" Print 'match', m, m.greaves () and: print 'no match' 'print' search start 'm = regex.search (path) print' searched ' ] I'm not completely sure how speed it is! Regexp will not contain the [] regexp group. This will probably work -
\ w * / {010} And use only () for the group ( < Strong> Edit
Based on your edited question, I think what you want is that the directory name matches 0-3 events and then the name of a file also matches .
Only characters in file names (and optionally three character extensions)
^ ((?: [: \ W] + /) {0}} (\ w + (?: \. \ W {1,3})? $? It is huge but can be broken into two parts
This is what you already have
((?: [: \ W] + /) {0}} and what I add
(\ w + (:. \ W {1,3})?)? This is an optional filename at the end (if it is not optional then you can remove the last ? ) The file name can only be made of algebet only or it may extend to maximum 3 characters ^ to add
] + /) {0}} (\ w + (?: \. \ W {1,3})?)? $ ') & Gt; & gt; My_str =' fwefw / wfwf / wefwf / dde .cdf '> gt; Pat.search (my_str) .groups () (' fwefw / wfwf / wefwf / ',' dde.cdf ')> My_str =' Fwefw / dde.cdf '>> / Html>
Comments
Post a Comment