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 February 15th, 2013, 11:34 AM
KevinHunter KevinHunter is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 KevinHunter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 13 sec
Reputation Power: 0
Other - 'net Regex Help

Hi folks , Im new to regex and was hoping someone might be able to give me some advice.

Im trying to use regex in VB.Net to split a string whenever there is a space except when it between quotes. I also want to keep the quotes.

I tried using \s+(?=([^""]*""[^""]*""[^""]*)*$|[^""]*$)

and it works on most string but here are a few lines that it doesnt work on !

/config/userctrl/A/enc "X001" "X101" "X201" "X300"

I want to get

/config/userctrl/A/enc
"X001"
"X101"
"X201"
"X300"

But get

/config/userctrl/A/enc
"X300"
"X001"
"X300"
"X101"
"X300"
"X201"
"X300"
"X300"

Same thing happens with

/config/userctrl/A/btn "O40" "O42" "X201" "X300" "P0051" "P0052" "P0053" "P0058"

and /ch/01/config "Drum Room" 2 CY 1
gives me
/ch/01/config
"Drum Room" 2 CY 1
"Drum Room"
2
CY
1

Where am I going wrong ???
Thanks in advance for any help you can give

Kev

Reply With Quote
  #2  
Old February 15th, 2013, 02:16 PM
requinix's Avatar
requinix requinix is offline
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,711 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 4 Days 6 h 45 m 48 sec
Reputation Power: 8969
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
Actually the expression is correct: it's your output that's wrong.

The parentheses you used meant that the regex is capturing whatever was matched.
Code:
/config/userctrl/A/enc ' segment
"X300"                 ' capture
"X001"                 ' segment
"X300"                 ' capture
"X101"                 ' segment
"X300"                 ' capture
"X201"                 ' segment
"X300"                 ' capture
"X300"                 ' segment


There may be an option in .NET where you can exclude the captured groups and keep only the actual split segments themselves, but you can just as easily make that group not capture.
Code:
"\s+(?=(?:[^""]*""[^""]*""[^""]*)*$|[^""]*$)"

Reply With Quote
  #3  
Old February 15th, 2013, 03:34 PM
KevinHunter KevinHunter is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 2 KevinHunter User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by requinix
Actually the expression is correct: it's your output that's wrong.

The parentheses you used meant that the regex is capturing whatever was matched.
Code:
/config/userctrl/A/enc ' segment
"X300"                 ' capture
"X001"                 ' segment
"X300"                 ' capture
"X101"                 ' segment
"X300"                 ' capture
"X201"                 ' segment
"X300"                 ' capture
"X300"                 ' segment


There may be an option in .NET where you can exclude the captured groups and keep only the actual split segments themselves, but you can just as easily make that group not capture.
Code:
"\s+(?=(?:[^""]*""[^""]*""[^""]*)*$|[^""]*$)"


Worked perfectly

Thank you for your help.

Kev

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreRegex Programming > Other - 'net Regex Help

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