asp.net regex find items in quotes

  • Thread starter Luis Esteban Valencia
  • Start date
L

Luis Esteban Valencia

hello quite a simple one if you understand regular expressions vbscript and
..net, probably quite hard if you don't

i have a single line input which offers classic search functionality, so if
someone puts something in quotes i.e "A Gibbon" i want to extract that prior
to using the rest of the string

what i need is a regex string that'll turn a postback string eg "A Gibbon"
"A Baboon" "George Bush" doris day into a csv array

("A Gibbon", "A Baboon", "George Bush", "doris", "day")

i can probably handle the doris day after i have got the quoted items

sub btnSearch_clicK()
dim strtext as string = inpSearch.text
dim srchArr as string
so dim myRegEx as new regEX( .....find all items in quotes)

srchArr = myRegEx.Replace( strtext, ...... )

any ideas?
 
B

BillGatesFan

I believe there was an article similiar to this in the Nov. 2004 Visual
Studio magazine. "Parsing text files using Regular Expressions". And I
said to myself. Who in the world would need to do that! There has to be
an easier way. Now I see that I was wrong. Sorry.

My suggestion is go to the magazine site and search for the article. It
might help
 
M

MWells

Not being a regex expert myself, the easy hack would be to do it in two
passes.

Pass 1: Get the quoted strings...

use regex... (\".*?\")
means: "get me anything that begins with a quote, maybe contains some
characters, and ends with a quote. no backtracking."
iterate through the groups
append these to your array
then replace all of the quoted strings with a space to avoid re-matching on
pass 2

Pass 2: Get the non-quoted strings...

use regex... ([^\s]+)
means: "get me any sequence of non-whitespace characters."
iterate through the groups
append these to your array


You might also have better success posting this in a regex-specific
newsgroup, or Google "csv regex" which is closely related to what you're
pursuing.

/// M
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top