Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] RegExp for parsing search strings
- From: paul at juniperwebcraft.com (Paul Novitski)
- Subject: [Javascript] RegExp for parsing search strings
- Date: Fri Apr 28 18:27:52 2006
At 03:19 PM 4/28/2006, Scott Reynen wrote: >On Apr 28, 2006, at 4:22 PM, Paul Novitski wrote: > >>My first attempt was something like this: >> >> /((\"[^\"]+\")|( [^ ]+ ))+/ >> >>one or more >> (quotes surrounding one or more non-quote characters) >>or >> (spaces surrounding one or more non-space characters) > >The following seems to work in PHP: > ><? > > $text = 'one "two three" " four " five six'; > > preg_match_all( '#(?:"([^"]+)")|([^ ]+)#' , $text , $matches ); > > echo( '<pre>' ); > print_r( $matches ); > echo( '</pre>' ); *Bonk* Scott, thanks for making me realize that I was barking up the wrong tree. I was using preg_split() instead of preg_match_all(). preg_split() finds delimiters and preg_match_all() finds the words themselves. Both your and my regular expressions work with preg_match_all(): http://juniperwebcraft.com/test/preg_split_Reynen01.php http://juniperwebcraft.com/test/preg_split_Novitski01.php but not with preg_split(). My own RegExp gives at least a partial result with preg_split() but that's probably coincidence; I need to start from scratch. Regards, Paul
- Follow-Ups:
- [Javascript] RegExp for parsing search strings
- From: Steve Clay
- [Javascript] RegExp for parsing search strings
- References:
- [Javascript] RegExp for parsing search strings
- From: Paul Novitski
- [Javascript] RegExp for parsing search strings
- From: Triche Osborne
- [Javascript] RegExp for parsing search strings
- From: Paul Novitski
- [Javascript] RegExp for parsing search strings
- From: Scott Reynen
- [Javascript] RegExp for parsing search strings
- Prev by Date: [Javascript] RegExp for parsing search strings
- Next by Date: [Javascript] RegExp for parsing search strings
- Previous by thread: [Javascript] RegExp for parsing search strings
- Next by thread: [Javascript] RegExp for parsing search strings
- Index(es):