472,952 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

Search string parsing

Hello,

I am having a hard time spliting a string into an array for use in a
search. Here is the situation. The user will input a search string.
Normally I can just split the string by "split /\s+/, $string".
However, I want to allow the user to put words so they appear and are
searched together ie. "search this" would be searched as one term and
not "search" and then somewhere else "this", etc. So if a user enters
something like this:

how do I "search this" and split

How do I split this into an array of:

how
do
I
search this
and
split

Thanks

Fritz
Jul 19 '05 #1
1 5163
flam wrote:
I am having a hard time spliting a string into an array for use in
a search. Here is the situation. The user will input a search
string. Normally I can just split the string by
"split /\s+/, $string". However, I want to allow the user to put
words so they appear and are searched together ie. "search this"
would be searched as one term and not "search" and then somewhere
else "this", etc. So if a user enters something like this:

how do I "search this" and split

How do I split this into an array of:

how
do
I
search this
and
split


This is one way:

my @array;
push @array, $+ while $string =~ /"([^"]*)"|(\S+)/g;

It should be noted that you asked a Frequently Asked Question, so a
more complete answer is available in the Perl FAQ: "How can I split a
[character] delimited string except when inside [character]?"

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
15
by: Freddie | last post by:
Happy new year! Since I have run out of alcohol, I'll ask a question that I haven't really worked out an answer for yet. Is there an elegant way to turn something like: > moo cow "farmer john"...
15
by: SK | last post by:
Hey folks, I am searching for a string (say "ABC") backwards in a file. First I seek to the end. Then I try to make a check like - do { file.clear (); file.get(c); file.seekg(-2,...
4
by: Axel | last post by:
Is it possible to write a Stored Procedure that takes a string of search keywords as argument and returns the recordset? At the mo I am passing the WHERE String as argument. I got this...
7
by: Bonj | last post by:
In making a ternary search tree to identify as fast as possible the type of word passed in to the algorithm, for instance sp_help -> 1 (procedures), select -> 2 (keywords), sysobjects -> 3 (system...
1
by: Raterus | last post by:
Does anyone know of some code samples that will parse a string field into an array of strings, but do it like a search engine would. I'm sure this would be fun to do it myself, but if an algorithm...
6
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
8
by: Sham | last post by:
I am trying to perform the following query on a table that has been indexed using Full Text Search. The table contains multiple columns than have been indexed. (Below, all xml columns are...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.