![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Regular Expression question | Katkota | UNIX for Dummies Questions & Answers | 6 | 05-14-2008 12:23 PM |
| question (regular expression related) | metalwarrior | UNIX for Dummies Questions & Answers | 1 | 02-03-2008 07:51 PM |
| Regular expression question | umen | Shell Programming and Scripting | 7 | 11-21-2007 05:45 PM |
| Regular Expression Question | Krispy | UNIX for Dummies Questions & Answers | 3 | 01-20-2006 06:36 AM |
| question about regular expression | brentdeback | Shell Programming and Scripting | 0 | 11-14-2005 12:04 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Thanks Radoulov
I was looking for only simple RE string not perl. something like: [^\n\r]*/([^/\n\r]*)/[^/\n\r]* |
| Forum Sponsor | ||
|
|
|
|||
|
Nothing wrong with your post, i just can't use a code, it must be one line for each request with no perl, just one line of RE so if i apply this RE to the line i'm trying to extract the field from, it should produce the results i'm looking for.
To make my request more clear, I'm using this link to confirm the result by entering the string & the RE then i see the results: Jakarta Regexp - Jakarta Regexp Applet |
|
|||
|
Regular expressions by themselves simply match something; they don't "extract". You can use them to identify strings which match a particular pattern; for example, whether the input has at least two slashes, and a string of non-slashes between those two slashes. However, the regular expression by itself does not as such allow you to extract part of the match (in the example, the string between the slashes). That's why you keep receiving replies which involve some sort of code -- it depends on the capabilities of the tool you use how you would use the regular expressions to extract any part of the match (in this thread as well as your original thread).
Thanks for the pointer to the Jakarta regex demo; the fact that you are using this makes a world of a difference. If that tool allows for extracting a parenthesized subexpression, then your second problem can be solved, but the regular expression needs to look at (and, by extension, "extract") most or all of the context to know whether a particular slash is the last one in the test string. So you can use /([^/]*)/[^/]*$ to tell whether there are two slashes before the end of the string, and if that is so, then the first parenthesized subexpression ($1 or \1 in many regex tools) will contain the parenthesized part between the slashes; but there is no way to construct a regular expression which alone picks out just the text between those two specific slashes. (The parentheses by themselves do not add anything to the regular expression, in this case; they are useful here only because of the side effect of capturing a substring of the match.) If you relax the requirement (perhaps because none of your examples contain more than two slashes) then you can match (and "extract") a string between two slashes, but without reference to context, the regex engine will pick the first place in the string where it finds text between two slashes. It appears that in all your examples, the first string between two slashes which is longer than three characters and which does not begin with a number is the parent directory; thus [^/0-9][^/][^/][^/][^/]* will coincidentally pick out that, but relying on this to work on a larger number of samples appears most precarious. Last edited by Neo; 05-18-2008 at 07:27 AM. |
|
|||
|
Thanks Era;
I'm sorry that i chose the wrong word to describe what i was looking for. I shouldn't say "extract", I should have said "match". SO, i will make my questions below as clear as possible: If i have these lines below /fs/pas/2007/4/6/2634210/admdat/examin /fs/pas/2007/4/6/2634210/admdat2/stat /fs/pas/2008/2/3/2634210/admdat3/data /fs/pas/2007/4/6/2634210/im_2/0b.dcm I would like to create 2 REs to run it against any of these lines "strings" using Apache link Jakarta Regexp - Jakarta Regexp Applet , so the results would be: 1. One RE to match the directory before last such "admdat, admdat2, im_2" 2. Another RE to match the date in each string such "2007/4/6, 2008/2/3" |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|