473,322 Members | 1,314 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,322 software developers and data experts.

Need Help (Regular Expressions)

hi

I've a got a problem
i must split a string (the split separator is a space)

Issue : spaces that should be taken into account are those which are not between quotes (")

example
$ligne = 0126878 "my name" "my_name_without_space" 12356 "a b c d e" "f g h i j"

after the split into @var, the result should be
$var[0] = 0126878
$var[1] = "my name"
$var[2] = "my_name_whithout_space"
$var[3] = 12356
$var[4] = "a b c d e"
$var[5] = "f g h i j"

i tried a lot of regexp but i'm a little bit confused at this point and can't get none of them working

if someone could help me, that would be great !

thanks
Sep 26 '06 #1
2 1302
I know it's not very cool, but the following solution should work:

Expand|Select|Wrap|Line Numbers
  1. my $line = '0126878 "my name" "my_name_without_space" 12356 "a b c d e" "f g h i j"';
  2.  
  3. # get the number in the format "0126878"
  4. $line =~ s/(\d+)/\"\1\"/ig;
  5.  
  6. # replace the space " " separating the data with a ";"
  7. $line =~ s/\"\s\"/\";\"/ig;
  8.  
  9. # now remove all of the "
  10. $line =~ s/\"//ig;
  11.  
  12. # the line looks like this now:
  13. # 0126878;my name;my_name_without_space;12356;a b c d e;f g h i j
  14.  
  15.  
  16. # split it by the ;
  17. my @var = split/;/,$line;
  18.  
  19.  
Sep 29 '06 #2
thanks for the reply, but meanwhile i found the solution

my @var = ($ligne =~ m/("[^"]+"|\S+)/g);
Sep 29 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Michael McGarry | last post by:
Hi, I am horrible with Regular Expressions, can anyone recommend a book on it? Also I am trying to parse the following string to extract the number after load average. ".... load average:...
1
by: Showjumper | last post by:
I need a regulr expression that cn be used to find <a> tags with the href attribute set to mailto:. I need to be to search out all the email addresses in the text of the pages in a website. So for...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
2
by: news.microsoft.com | last post by:
I need help design a reg exp. I am parsing an html file to get the input values, here is one example <input VALUE="Staff Writer" size=60 type="text" name="author"> Can I grab the value "Staff...
7
by: norton | last post by:
Hello, Does any one know how to extact the following text into 4 different groups(namely Date, Artist, Album and Quality)? - Artist - Album Artist - Album - Artist - Album - Artist -...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
3
by: a | last post by:
I'm a newbie needing to use some Regular Expressions in PHP. Can I safely use the results of my tests using 'The Regex Coach' (http://www.weitz.de/regex-coach/index.html) Are the Regular...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
12
by: FAQEditor | last post by:
Anybody have any URL's to tutorials and/or references for Regular Expressions? The four I have so far are: http://docs.sun.com/source/816-6408-10/regexp.htm...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.