in reply to extract text between slashes
m{/(.*?)/}
A second issue is if the string has empty slots between slashes, such as the string "%///US1252691001". You probably want to be able to return an empty result in this case, so I changed your use of .+ (one or more) to .* (zero or more) characters. Otherwise, you might get a match back of "/" for strings like my example.
Update: As others mentioned but I didn't parse correctly, to get the THIRD field (e.g., "~/~/THIS/~") takes a little more work. Instead of a bunch of complicated lookaheads and lookbehinds, or switching to a split() instead, I would just parse through. This has the advantage of easily changing the pattern to capture the other fields if the requirements change.
m{/.*?/(.*?)/}
--
[ e d @ h a l l e y . c c ]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: extract text between slashes
by johngg (Canon) on Oct 31, 2007 at 16:44 UTC | |
|
Re^2: extract text between slashes
by EvanK (Chaplain) on Oct 31, 2007 at 17:00 UTC | |
by johngg (Canon) on Oct 31, 2007 at 19:50 UTC | |
|
Re^2: extract text between slashes
by RaduH (Scribe) on Oct 31, 2007 at 17:21 UTC |