Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Javascript] RegExp for parsing search strings


  • From: sclay at ufl.edu (Steve Clay)
  • Subject: [Javascript] RegExp for parsing search strings
  • Date: Fri Apr 28 19:56:50 2006

Friday, April 28, 2006, 7:27:42 PM, Paul wrote:
> preg_split() finds delimiters and preg_match_all()
> finds the words themselves.

preg_split() called with the flags as I sent will also return the
captures, I just forgot to capture the expression in the e-mail I set you
(that's what I get for throwing it together before running out the door at
5 on Friday).

Anyway, you wanted this in JS? This will handle single or double quotes and
allow the opposite inside.

var
  test = ' apple "\'banana crust" dand\'elion"eleph\'ant " fawn grass " fandango',
  m = test.match(/"[^"]+"|'[^']+'|[^\s'"]+/g);
for (var i=0, l=m.length; i<l; i++) {
  m[i] = m[i].replace(/^['"]|['"]$/g, '');
}
alert(m);

Steve
-- 
http://mrclay.org/