Re: Regular Expression Troubles
- From: Ed Morton <morton@xxxxxxxxxxxxxx>
- Date: Wed, 21 Dec 2005 07:47:17 -0600
mross462@xxxxxxxxx wrote:
To clarify a little bit more, basically I need to find what is inbetween the punctuation ( ".", "#" and "{" ) in these cases:
beforeperiod.classname{ .classname{ #classname{
and what is before the colon in this case:
classname:aftercolon{
The regular expression as stated above is returning the full "beforeperiod.classname{" string , which I can't really undertand, as the first character it looks for.
Essentially it doesn't matter whether I get the punctuation as I can use either sed or awk to edit those strings.
Example:
Given the following:
Div.toolbar{
I need it to return:
.toolbar{ or
toolbar
Well, this will do it for the samples you posted:
$ cat file
beforeperiod.classname{
..classname{
#classname{
classname:aftercolon{
Div.toolbar{
$ cat getclass.awk
/[.#][[:alnum:]]*{/ { split($0,a,/[.#{]/); print a[2] }
/[[:alnum:]]*:[[:alnum:]]*{/ { split($0,a,/[:]/); print a[1] }
$ awk -f getclass.awk file
classname
classname
classname
classname
toolbarbut it's not exactly robust to white space or other text on the same line, or the same patterns appearing in comments, etc... so if your sample input doesn't represent your real input then it may not work as intended.
Ed. .
- References:
- Regular Expression Troubles
- From: mross462
- Re: Regular Expression Troubles
- From: Ed Morton
- Re: Regular Expression Troubles
- From: Kevin Collins
- Re: Regular Expression Troubles
- From: mross462
- Re: Regular Expression Troubles
- From: Ed Morton
- Re: Regular Expression Troubles
- From: mross462
- Regular Expression Troubles
- Prev by Date: Re: Regular Expression Troubles
- Next by Date: Help needed with awk
- Previous by thread: Re: Regular Expression Troubles
- Next by thread: Length of command to execve
- Index(es):
Relevant Pages
|
|