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 July 9th, 2011, 04:29 PM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
Other - Some mistake with quantifier and look-ahead assertion

Hi,

I don't unterstand why my expression doesn't work and hope somebody can help me.

In the string "(*.ini; *.exe; )" the first "; " should be found, the second not. The search expression is "; *(?!\))". But this way the second semicolon without space is matched. There should only be one match: the first "; ".

What's the mistake and how can I do it right? Thanks

Reply With Quote
  #2  
Old July 9th, 2011, 10:34 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,873 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 44 m 28 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Regular expressions always try to match. Your space* means that it will try to match as many spaces as possible, but if the expression fails later on, the engine will backtrack and match fewer spaces.
In your case, the space* matches zero spaces (which is allowed because *=0 or more) and the negative lookahead passes (because the next character is a space, not a closing parenthesis).

Using space+ will fix this instance, but you'll have the same problem if there are two or more spaces.

What are you trying to match? The filename patterns?

Reply With Quote
  #3  
Old July 10th, 2011, 12:07 AM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
Thanks for the help. Now it's clear to me.

I want to check the validity of a string you can pass to a file-save dialog like "All supported formats (*.abc; *.def; *.ghi)". The * in the search expression is right, there shall be allowed 0 to infinity spaces. So the problem remains. Is there a solution?

Reply With Quote
  #4  
Old July 10th, 2011, 06:57 AM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,873 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 44 m 28 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
The dialogs I know use the two parts separately: the display text and the actual filename filter...

Anyways, how about
Code:
\([^\s;)]+(;\s*[^\s;)]+)*\)$

Reply With Quote
  #5  
Old July 10th, 2011, 03:27 PM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
This works for the part in parantheses. But I have the same issue on a larger scale: elements seperated by a separator.

You can see the function I use, if you google for "autoit reference FileSaveDialog". Multiple filters can be stated in the form of
Code:
All (*.*)|Text files (*.txt)


So how can I build an expression in which I only have to write a subpattern once with a seperator after it, but the seperator only being matched if the end does not follow? To make an easy example:
Code:
string|string|string
has to match,
Code:
string|string|stng
(stands for error in subpattern) and
Code:
string|string|string|
not.

Reply With Quote
  #6  
Old July 10th, 2011, 05:39 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,873 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 7 h 44 m 28 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Before I do anything else:

Is that the actual string you're working with? The full story? Is there anything else you haven't said that will invalidate anything I say because I'm giving the right answer to the wrong question?
Because twice now you've changed the problem. Before it was just filename patterns, then it was a filter, and now it's a set of filters, and I don't really feel like answering one question after another if you don't actually need all those answers.

Reply With Quote
  #7  
Old July 11th, 2011, 04:36 AM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
I wrote a program in which you can export some kind of log file. The user could want any extension he preferes. Therefore in the INI file for strings in a specific language you can set the "filter" parameter of the FileSaveDialog function.

So there could be, e.g.
Code:
All Files (*.*)|Text files (*.txt)|Log files (*.log)|Supported files (*.txt; *.log)


The issue is the same on different scales:
- Between ^ and $ there are elements with a specific pattern, separated by | (e.g. "All Files (*.*)")
- Nested in the other pattern between ( and ) there are elements with a specific pattern, separated by ";\s*" (e.g. "*.log").

What I want to do is to validate the string. I thought there must be a way I don't have to write every subpattern twice.

Reply With Quote
  #8  
Old July 26th, 2011, 01:13 PM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
In case somebody reads this thread and wants to get an answer:

Reply With Quote
  #9  
Old July 26th, 2011, 01:15 PM
jay-em jay-em is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2011
Posts: 6 jay-em User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 27 m 22 sec
Reputation Power: 0
I found one and documented it there: http://regexlib.com/REDetails.aspx?regexp_id=3325.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Other - Some mistake with quantifier and look-ahead assertion

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