Regex Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreRegex Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 23rd, 2008, 07:44 PM
videoediting videoediting is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 199 videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level)videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level)videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level)videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level)videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level)videoediting User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Day 19 h 50 m 44 sec
Reputation Power: 42
Arrow Those Tricky Stars!

Ok, I figured out the strings myself, but I don't understand why my solution doesn't work for comments...

I am trying to detect /* whatever */

Here is my regular expression...
/\*[^(\*/)]*\*/

... I would expect that regular expression to work, but it doesn't...

This regular expression behaves as expected, but not as desired:
/\*[^(/)]*\*/

Why won't the first regular expression match? What can I do to make it match?

Reply With Quote
  #2  
Old November 24th, 2008, 01:12 AM
prometheuzz prometheuzz is offline
User 165270
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 497 prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level)prometheuzz User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 5 Days 10 h 14 m 35 sec
Reputation Power: 936
That is because character classes always match a single character.
So the class [^(\*/)] will match any character except '(', '*', '/' or ')'. As you see, the "normal" meta characters like '(' and ')' don't group characters inside a character class as they do outside a character class. Also, the '*' does not need escaping inside a character class and it just matches the character '*'.

All of that said, you can match comments like this:

Code:
(?s)/\*((?!\*/).)*\*/

Last edited by prometheuzz : November 24th, 2008 at 01:14 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Those Tricky Stars!

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap