regex for one "two three" four 
Author Message
 regex for one "two three" four

I need a regular expression for a string that may or may not have
quotes.  For example:

one two three
"one" "two" "three"
"one" two three
... you get the picture
  should be parsed as 'one', 'two', 'three'

one "two three" four
"one" "two three" four
"one" "two three" "four"
...
  should be parsed as 'one', 'two three', 'four'

Thanks for the help.

------------
Mark Haskamp      
http://www.*-*-*.com/ ~mhaskamp

"Freedom of the press is for those who own one."
   -- A.J.Liebling



Sat, 18 Mar 2000 03:00:00 GMT  
 regex for one "two three" four

: I need a regular expression for a string that may or may not have
: quotes.  For example:

: one two three
: "one" "two" "three"
: "one" two three
: .... you get the picture
:   should be parsed as 'one', 'two', 'three'

: one "two three" four
: "one" "two three" four
: "one" "two three" "four"
: ....
:   should be parsed as 'one', 'two three', 'four'

start with

Perl FAQ, part 4:

   "How can I split a [character] delimited string except
    when inside [character]?"

and modify it for your [character]s

: Thanks for the help.

Uh huh.

--
    Tad McClellan                          SGML Consulting

    Fort Worth, Texas



Sat, 18 Mar 2000 03:00:00 GMT  
 regex for one "two three" four

Dear Mark,

Here's a script that does what you require.

while (<>) {
        while (/"([^"]*)"\s*|(\w+)\s*/g) {
                print "$1\n" if $1;
                print "$2\n" if $2;
        }

Quote:
}

Regards,

Mick



Sun, 19 Mar 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing two lists to a "sub"

2. use strict "refs": # two questions

3. "character class ""bug""

4. "cat"-ing three files into three files.

5. Group capturing and "nested" regex

6. Perl 4/5 regex "bug" revisited

7. regex for "no character repeating itself"

8. One question about useage "<>"

9. Group capturing and "nexted" regex

10. "Unmatched () in regex" error

11. Substitute across lines in "one liner"

12. "Simple" regex question

 

 
Powered by phpBB® Forum Software