in reply to C/C++ function parsing
G'day ssriganesh,
Welcome to the monastery.
To match the characters between the parentheses, I'd use '[^)]*' which matches any character except the closing parenthesis because '.' matches any character including a closing parenthesis.
Working with the limited example input you've provided, here's how I might have coded this. I've included additional code to join a captured multi-line: not stated, but that may be what you want.
#!/usr/bin/env perl -l use strict; use warnings; my $f1 = 'static gboolean g::ber_read(wtap *wth, int *err)'; my $f2 = 'static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size)'; for ($f1, $f2) { print "Function: $_"; /([:\w]+\([^)]*\))/m; print "Captured: $1"; # if you want multi-line reduced to single-line: (my $no_newlines = $1) =~ y/\n/ /; print "Lines joined: $no_newlines"; }
Output:
Function: static gboolean g::ber_read(wtap *wth, int *err) Captured: g::ber_read(wtap *wth, int *err) Lines joined: g::ber_read(wtap *wth, int *err) Function: static void ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size) Captured: ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size) Lines joined: ber_set_pkthdr(struct wtap_pkthdr *phdr, int packet_size +)
-- Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: C/C++ function parsing
by ssriganesh (Initiate) on Jan 13, 2014 at 08:14 UTC | |
by ImJustAFriend (Scribe) on Jan 13, 2014 at 12:56 UTC | |
by kcott (Archbishop) on Jan 13, 2014 at 13:41 UTC | |
by ssriganesh (Initiate) on Jan 15, 2014 at 06:55 UTC |