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?
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?
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: - $_ = 'this <is> a test <to see> what happens';
-
@d = split(/<([\w ]+)>/);
-
print "$_\n" for @d;
returns: - this
-
is
-
a test
-
to see
-
what happens
So an expression like Rincevent posted should be more like what you want: - @words = ($var =~ /<([^>]+)>/g);
or without the extra parenthesis: - @words = $var =~ /<([^>]+)>/g;
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: =?Utf-8?B?YWxleA==?= |
last post by:
I have the following database schema:
posts
-------
post_id
post_name
posts_tags
-------------
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
|
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...
|
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...
| |