Re: Regular Expression Troubles



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
toolbar

but 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.
.



Relevant Pages

  • Re: Create Forms via Parameter
    ... need the classname to retrieve a class registered via RegisterClasses. ... Function ShowFormByName(const formname: String; ... variable, the form reference, and that can be had the way shown above. ... The VCL contains a suitable class registry, ...
    (borland.public.delphi.language.objectpascal)
  • Re: DirectCom.dll: vb sample -> vfp
    ... GETINSTANCE erwartet als String-Parameter jeweils den Pointer ... Dim D As Object, FName As String, ClassName As String ... ClassName = StrConv'nach ANSI ...
    (microsoft.public.de.fox)
  • Re: String problem VS 2005
    ... the console the Classname and the text in the notepad window. ... The first output to the console is "N" and not ... I dont understand how to work with all the C++ string format. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Regular Expression Troubles
    ... The regular expression as stated above is returning the full ... "beforeperiod.classname{" string, which I can't really undertand, as ...
    (comp.unix.questions)
  • Re: Get Path Where A Class Is Located
    ... Call it jwhich. ... And then use the class file compiled from the code below: ... @param className The full name of the class. ... public static String which ...
    (comp.lang.java.programmer)