473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

excluding search string in regular expressions

Hello,

Following Problem:

find only occurances, where in the line are'::' characters and
the former line is not equal '**/'

so 2) and 3) should be found and 1) not.

1)
"""
**/
void C::B
"""

2)
"""

void C::B
"""

3)
"""
*/
void C::B
"""

I tried something
"\*\*/\n.*::"

But this is the opposite.

So my question is: how can I exclude a pattern?

single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::

thank you in advance,
--
Franz Steinhaeusler
Jul 18 '05 #1
9 2869
On Thu, 21 Oct 2004 13:36:46 +0200, Franz Steinhaeusler
<fr*****************@utanet.at> wrote:

single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::


Sorry,
is this the solution (simple concatenating [^*][^*][^/]\n.*:: ?
The background:
I want to scan cpp file, whether the have a doxygen comment already:
It should find all postitions, where this is missing:

ok

doxygen comment
**/
void CBs::InitButtonPanel (int progn1, int progn2)

the problem is to find the method or function definition, and for
that, I need a regex.
it should ignore blabla::InitButtonPanel(a, b);

So a mark is that if there is a semikolon at the end,
it is no function or method defininition.

So I would need
[^*][^*][^/]\n.*[)]*[^;]
but this is not working.

Thank you again in advance!
--
Franz Steinhaeusler
Jul 18 '05 #2
Franz Steinhaeusler wrote:
On Thu, 21 Oct 2004 13:36:46 +0200, Franz Steinhaeusler
<fr*****************@utanet.at> wrote:

single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::
Sorry,
is this the solution (simple concatenating
[^*][^*][^/]\n.*:: ?


That should do, though it's admittedly far from elegant; I, too, would like to see a nicer solution.
The background:
I want to scan cpp file, whether the have a doxygen
comment already: It should find all postitions, where
this is missing:

ok

doxygen comment
**/
void CBs::InitButtonPanel (int progn1, int progn2)


In this case, I'd replace \n with \w*, meaning any amount of whitespace.
Jul 18 '05 #3
On Thu, 21 Oct 2004 14:40:24 +0200, "Mitja" <nu*@example.com> wrote:
Franz Steinhaeusler wrote:
On Thu, 21 Oct 2004 13:36:46 +0200, Franz Steinhaeusler
<fr*****************@utanet.at> wrote:

single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::


Sorry,
is this the solution (simple concatenating
[^*][^*][^/]\n.*:: ?


That should do, though it's admittedly far from elegant; I, too, would like to see a nicer solution.
The background:
I want to scan cpp file, whether the have a doxygen
comment already: It should find all postitions, where
this is missing:

ok

doxygen comment
**/
void CBs::InitButtonPanel (int progn1, int progn2)


In this case, I'd replace \n with \w*, meaning any amount of whitespace.


Hello, thank you.

Oh, not really right (about finding c function/method definition):

[^*][^*][^/]\w*.*[)]*[^;]
if func()
{

would also be found.

A more common solution for detecting functions/Methods would be fine.

[^*][^*][^/]\w*--c-method/function/definition
--
Franz Steinhaeusler
Jul 18 '05 #4
Mitja <nu*@example.com> wrote:
Franz Steinhaeusler wrote:
Franz Steinhaeusler wrote:
[...]
single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::


Sorry,
is this the solution (simple concatenating
[^*][^*][^/]\n.*:: ?


That should do, though it's admittedly far from elegant; I, too,
would like to see a nicer solution.


It won't work correctly. Franz needs a sub-expression that
matches anything which is not "**/". However, [^*][^*][^/]
is a character-wise negation, not word-wise. It doesn't
match "**/", but neither does it match "xx/", nor any other
string which has only one or two of the characters at the
right position.

What you need is a "negative look-behind assertion". The
following Python-RE will do: (?<!\*\*/)\n.*::
Remember to use raw string notation, or you need to double
the backslashes:

my_re_str = r"(?<!\*\*/)\n.*::"
my_re_obj = re.compile(my_re_str)

Note that you might want to use \s* instead of \n, so any
amount of whitespace (including newlines) is matched, not
just one single newline.

For more information about regular expressions supported by
Python, refer to the Library Reference manual:

http://docs.python.org/lib/re-syntax.html

Best regards
Oliver

--
Oliver Fromme, Konrad-Celtis-Str. 72, 81369 Munich, Germany

``All that we see or seem is just a dream within a dream.''
(E. A. Poe)
Jul 18 '05 #5
>
A more common solution for detecting functions/Methods would be fine.


Maybe you should go for a real parser here - together with a
C-syntax-grammar. Trying to cram this stuff into regexps is bound for not
catching special cases. And its gereally difficult to have a regexp _not_
macht a certain word.

Another approach would be to look for closing comments and function
definitions in several rexes, and use python-logic:

if doxy_close_rex.match(line):
line = lines.next()
if fun_def_rex.match(line):
....
--
Regards,

Diez B. Roggisch
Jul 18 '05 #6
On Thu, 21 Oct 2004 13:36:46 +0200, Franz Steinhaeusler <fr*****************@utanet.at> wrote:
Hello,

Following Problem:

find only occurances, where in the line are'::' characters and
the former line is not equal '**/'

so 2) and 3) should be found and 1) not.

1)
"""
**/
void C::B
"""

2)
"""

void C::B
"""

3)
"""
*/
void C::B
"""

I tried something
"\*\*/\n.*::"

But this is the opposite.

So my question is: how can I exclude a pattern?

single characters with [^ab] but I need not(ab)

not_this_brace_pattern(\*\*/\n).*::

thank you in advance,


To look back a line, I think I'd just use a generator, and test current
and last lines to get what I wanted. E.g., perhaps you can adapt this:
(I am just going literally by
"""
find only occurances, where in the line are'::' characters and
the former line is not equal '**/'
"""
which doesn't need a regex)
def findem(lineseq): ... getline = iter(lineseq).next
... curr = getline().rstrip()
... while True:
... last, curr = curr, getline().rstrip()
... if '::' in curr and last != '**/': yield curr
...

I made a file, modifying your data a little:
print '----\n%s----'% file('franz.txt').read() ----
1)
"""
**/
void C::B -- no (1)
"""

2)
"""

void C::B -- yes (2)
"""

3)
"""
*/
void C::B -- yes (3)
"""
----

Here's what the generator returns:
for line in findem(file('franz.txt')): print repr(line)

...
'void C::B -- yes (2)'
'void C::B -- yes (3)'
Regards,
Bengt Richter
Jul 18 '05 #7
On Thu, 21 Oct 2004 15:32:37 +0200, "Diez B. Roggisch"
<de************@web.de> wrote:

A more common solution for detecting functions/Methods would be fine.
Maybe you should go for a real parser here - together with a
C-syntax-grammar. Trying to cram this stuff into regexps is bound for not
catching special cases. And its gereally difficult to have a regexp _not_
macht a certain word.


Hello Diez,

thanks, yes, it is difficult for "not" find a searchstring in regex ;)

I only want to find a regex for an editor (which is written in python)
to have a common function (of course it cannot be so accurate as a
parser) to find a function/method defininition.
Another approach would be to look for closing comments and function
definitions in several rexes, and use python-logic:

if doxy_close_rex.match(line):
line = lines.next()
if fun_def_rex.match(line):
....


--
Franz Steinhaeusler
Jul 18 '05 #8
On 21 Oct 2004 13:28:28 GMT, Oliver Fromme <ol**@haluter.fromme.com>
wrote:
Mitja <nu*@example.com> wrote:
Franz Steinhaeusler wrote:
Franz Steinhaeusler wrote:
> [...]
> single characters with [^ab] but I need not(ab)
>
> not_this_brace_pattern(\*\*/\n).*::

Sorry,
is this the solution (simple concatenating
[^*][^*][^/]\n.*:: ?
That should do, though it's admittedly far from elegant; I, too,
would like to see a nicer solution.


Hello Oliver,
It won't work correctly. Franz needs a sub-expression that
matches anything which is not "**/". However, [^*][^*][^/]
is a character-wise negation, not word-wise. It doesn't
match "**/", but neither does it match "xx/", nor any other
string which has only one or two of the characters at the
right position.
yes, you are right, the approach above is false.

What you need is a "negative look-behind assertion".
??, sounds interesting ;)
The
following Python-RE will do: (?<!\*\*/)\n.*::
Remember to use raw string notation, or you need to double
the backslashes:

my_re_str = r"(?<!\*\*/)\n.*::"
my_re_obj = re.compile(my_re_str)

Note that you might want to use \s* instead of \n, so any
amount of whitespace (including newlines) is matched, not
just one single newline.

For more information about regular expressions supported by
Python, refer to the Library Reference manual:

http://docs.python.org/lib/re-syntax.html


(?<!...)
Matches if the current position in the string is not preceded by a
match for..

That is it.

Many thanks for your helpful reply,

--
Franz Steinhaeusler
Jul 18 '05 #9
On Thu, 21 Oct 2004 22:38:00 GMT, bo**@oz.net (Bengt Richter) wrote:

To look back a line, I think I'd just use a generator, and test current
and last lines to get what I wanted. E.g., perhaps you can adapt this:
(I am just going literally by
"""
find only occurances, where in the line are'::' characters and
the former line is not equal '**/'
"""
which doesn't need a regex)
def findem(lineseq):

... getline = iter(lineseq).next
... curr = getline().rstrip()
... while True:
... last, curr = curr, getline().rstrip()
... if '::' in curr and last != '**/': yield curr
...
[...]

Regards,
Bengt Richter


Hello Bengt,

thank you for suggesting this interesting approach,

regards
--
Franz Steinhaeusler
Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
4
by: higabe | last post by:
Three questions 1) I have a string function that works perfectly but according to W3C.org web site is syntactically flawed because it contains the characters </ in sequence. So how am I...
32
by: tshad | last post by:
Can you do a search for more that one string in another string? Something like: someString.IndexOf("something1","something2","something3",0) or would you have to do something like: if...
29
by: zoro | last post by:
Hi, I am new to C#, coming from Delphi. In Delphi, I am using a 3rd party string handling library that includes some very useful string functions, in particular I'm interested in BEFORE (return...
6
by: jcrouse | last post by:
Here is a sniplet from a text file game name mapp description "Mappy (US) year 198 manufacturer "Namco history "\nMappy (c) 03/1983 Namco. \n\n- TRIVIA: \n\nLicensed to Bally Midway for US...
7
by: Brian Mitchell | last post by:
Is there an easy way to pull a date/time stamp from a string? The DateTime stamp is located in different parts of each string and the DateTime stamp could be in different formats (mm/dd/yy or...
4
by: lucky | last post by:
hi there!! i'm looking for a code snipett wich help me to search some words into a particular string and replace with a perticular word. i got a huge data string in which searching traditional...
4
by: Eric | last post by:
Hi: How to i search ":" in a sentence. For eg: abc efg hij : kkk ddd lll fda fdasf jfdas fdas fsad When i read a line i want to skip those lines where ":" is present data = ts.ReadLine
11
by: dick.deneer | last post by:
I have a XML which specifies a Cobol copybook member. The XML is checked against a XSD. One of the xml attributes is the Cobol fieldname. The xsd constraints the value of this attribute to be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.