Hey Roy, here's a free tip: It is very likely to get responses like this
when making requests of the form "Please solve my problem!" without
showing and explaining *what you* have tried already and what your exact
problem with your approach is.
regards,
/W
Hi Jacek,
Thank you for the tip. Actually, this is not my homework. I just
started learning regular expression last night and came up with this
problem. I've tried many ways to parse this string but haven't
succeeded yet.
The problem that bugs me is the spaces inside the quotation marks and
the spaces outside of them. I don't know how to write an expression to
distinguish them. Of course I believe I can find other ways to parse
the string without using any regular expressions. But I am just
curious whether a simple expression can do the job.
Here are what I've tried:
Enter your regex: [^{},"]+
Enter input string to search: {"hello", "hello world",
"1hello-2*hello"}
I found the text "hello" starting at index 2 and ending at index 7.
I found the text " " starting at index 9 and ending at index 10.
I found the text "hello world" starting at index 11 and ending at
index 22.
I found the text " " starting at index 24 and ending at index
33.
I found the text "1hello-2*hello" starting at index 34 and ending at
index 48.
I found the text " " starting at index 50 and ending at index 51.
Enter your regex: [^{},"\s+]+
Enter input string to search: {"hello", "hello world",
"1hello-2*hello"}
I found the text "hello" starting at index 2 and ending at index 7.
I found the text "hello" starting at index 11 and ending at index 16.
I found the text "world" starting at index 17 and ending at index 22.
I found the text "1hello-2*hello" starting at index 34 and ending at
index 48.