473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

split query on tags

Hi,

givens lines of text such as:

the cat sat on the mat
the <var> sat on the mat
the <var> sat on the <my object>
the <var> sat on the <my object> and <action taken by cat>

I want to be able to return all instances of my variables (anything within <>). Sometimes the variable will be one word only (i.e <var>, but it may be several (i.e <action taken by cat>)


I can successfuly split the text for one word variables, and return it as follows:(where $array[$j] is a line of text)

@words= split /(<\w+>)/,$array[$j];


To make multiple variable matches I have tried

@words= split /(<(\w+\s*)+>)/,$array[$j];

so I'm saying word ,0 or more spaces, repeat multiple times. I've tried multiple variants but can't nail this one down.


any suggestions please?
Aug 16 '07 #1
2 1321
Not sure I follow the example, do you mean all the information you'll want to retrieve is between < and >?

because the split you're making should retrieve anything but the < and >
That's how i understand @words= split /(<(\w+\s*)+>)/,$array[$j] anyway?

From my attempts at split (not used to it, usually I use classical match),
seems anything you put in a group ( ) is considered as "not matching", or something.

so something very simple like /^the (.+) sat on the (.+) and (.+)$/ could achieve what you want? (when I tried it, I did get an empty first entry in the array, and I don't know what caused it).

Otherwise, going through a classical match:
@words = ($var =~ /^the (.+) sat on the (.+) and (.+)$/)
would get you the parameters in one version, or for the other version:
@words = ($var =~ /<([^>]+)>/g);

But maybe I'm not getting what you're trying to do altogether?
Aug 16 '07 #2
KevinADC
4,059 Expert 2GB
Using capturing parenthesis in the split functions regexp will capture the pattern along wth the rest of the data, but it's not much value unless you can differentiate the captured groups from the captured data, for example:

Expand|Select|Wrap|Line Numbers
  1. $_ = 'this <is> a test <to see> what happens';
  2. @d = split(/<([\w ]+)>/);
  3. print "$_\n" for @d; 
returns:

Expand|Select|Wrap|Line Numbers
  1. this 
  2. is
  3.  a test 
  4. to see
  5.  what happens
So an expression like Rincevent posted should be more like what you want:

Expand|Select|Wrap|Line Numbers
  1. @words = ($var =~ /<([^>]+)>/g);
or without the extra parenthesis:

Expand|Select|Wrap|Line Numbers
  1. @words = $var =~ /<([^>]+)>/g;
Aug 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tim | last post by:
Hi I want to be able to split the contents of a text field into two or maybe three columns. The text field contains text AND HTML mark-up. My initial thought was to find the middle character...
18
by: Wim | last post by:
Hi, I would like to make and put a query in my database by VB.NET code. Is this possible? Thanks for your help, wim
1
by: Andrew Tatum | last post by:
Alright, I have this table called Tags. The three columns of interest are Tags.Id, Tags.Name, Tags.ParentTagId This is the query I am currently using: Select Tags.Id, Tags.Name,...
6
by: Stan | last post by:
I am working on a database in ACCESS 2003. This is a simple DB with only one table. I have split the DB so I can upgrade and debug the front end before installing on my clients' computer. I used...
0
by: =?ISO-8859-15?Q?C=E9dric?= | last post by:
Hi all, I want to import a SQL script (SQLite) executing each queries separately. - I read the SQL file - I split the read string with the separator ";" - I execute each query string query...
22
by: SmokeWilliams | last post by:
Hi, I am working on a Spell checker for my richtext editor. I cannot use any open source, and must develop everything myself. I need a RegExp pattern to split text into a word array. I have...
1
by: shapper | last post by:
Hello, I have two tables, Tags and ArticlesTags, with the following columns: Tags TagID, Text ArticlesTags TagID, ArticleID I need to create a LINQ query to select all records in Tags...
2
by: =?Utf-8?B?YWxleA==?= | last post by:
I have the following database schema: posts ------- post_id post_name posts_tags -------------
2
by: shapper | last post by:
Hello, I have 3 tables with a many to many relationship: Professors ProfessorID, Age, ... Tags TagID, Name, ... ProfessorsTags ProfessorID, TagID How can I get all the professors and all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.