The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Regex Programming
|
Long regex, need some help
Discuss Long regex, need some help in the Regex Programming forum on Dev Shed. Long regex, need some help Regular expressions forum covering PCRE and POSIX techniques, practices, and standards. Regular expressions help shorten coding time by providing the ability to compact many lines of code into one string.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 20th, 2012, 01:51 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 5
Time spent in forums: 1 h 51 m 20 sec
Reputation Power: 0
|
|
|
Long regex, need some help
Hello everyone, I'm trying to pull the following out of a longer line of text and I'm having some troubles finishing.
I'm trying to get my regex to grab this whole chunk here:
Code:
[["ItemFlashlight","ItemWatch","ItemMap","ItemKnife","ItemEtool","ItemGPS","ItemHatchet","ItemCompass","ItemMatchbox","M9SD","ItemFlashlightRed","NVGoggles","Binocular_Vector","ItemToolbox","M4A1_AIM_SD_camo"],["ItemPainkiller","ItemMorphine","ItemSodaPepsi","FoodSteakCooked",["30Rnd_556x45_StanagSD",29],"30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD","30Rnd_556x45_StanagSD",["15Rnd_9x19_M9SD",12],["15Rnd_9x19_M9SD",10],"15Rnd_9x19_M9SD","15Rnd_9x19_M9SD","ItemBandage"]]
By using the following regex:
Code:
\[\[([\w|_|\""|,]*)\],\[([\w|_|\""|,|\[|\]]*)\]\],
But it only matches up to:
Code:
[["ItemFlashlight","ItemWatch","ItemMap","ItemKnife","ItemEtool","ItemGPS","ItemHatchet","ItemCompass","ItemMatchbox","M9SD","ItemFlashlightRed","NVGoggles","Binocular_Vector","ItemToolbox","M4A1_AIM_SD_camo"],["ItemPainkiller","ItemMorphine","ItemSodaPepsi",
Could anyone tell me what I seem to be missing, I know it has to do when it gets to the items wrapped in '[' style brackets but it's stumping me :/
|

August 20th, 2012, 02:08 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Hi,
A regex makes absolutely no sense in this case. This looks like a specific data format (JSON?), so you should use a proper parser. Or maybe you can do a simple text search?
Regular expressions are not the solution to every problem. Patterns like this with nested expressions are extremely difficult to describe with regexes -- or even not at all.
So it's very important to choose the right tool. Regular expressions are only appropriate for simple patterns like a date that can be described as a sequence of characters.
// I see that I've made the exact suggestion in your last thread. So you're really in love with regexes. 
Last edited by Jacques1 : August 20th, 2012 at 02:11 PM.
|

August 20th, 2012, 02:14 PM
|
|
Registered User
|
|
Join Date: Jul 2012
Posts: 5
Time spent in forums: 1 h 51 m 20 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Jacques1 Hi,
A regex makes absolutely no sense in this case. This looks like a specific data format (JSON?), so you should use a proper parser. Or maybe you can do a simple text search?
Regular expressions are not the solution to every problem. Patterns like this with nested expressions are extremely difficult to describe with regexes -- or even not at all.
So it's very important to choose the right tool. Regular expressions are only appropriate for simple patterns like a date that can be described as a sequence of characters.
// I see that I've made the exact suggestion in your last thread. So you're really in love with regexes.  |
lol no, I'm just new to this area, and I'm using a vb.net environment.
Since you suggest a different method, are there any tutorials you can link me to or possibly a practical example.
|

August 20th, 2012, 02:45 PM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
I can't give you practical examples without even knowing where this comes from.
If it's actually JSON, just look for a JSON parser for VB.net. If it's a different format, look for a parser for this format.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|