Hi,
Does anyone know if it's possible to use regular expressions to grab
all content between two words. For example....
------
This is some example text to illustrate my problem and here's another
my for you.
------
I want to grab all text between the words 'some' and 'my' with the
correct result being ' example text to illustrate '
The following doesn't work with either ereg or preg_match...
some([^(my)]+)my
Anyone got any ideas? Is this even possible with regular expressions?
Thanks in advance,
Paul Maunders www.fubra.com 3 1376
In article <11************ **********@g49g 2000cwa.googleg roups.com>,
"Paul" <pa***********@ gmail.com> wrote: Hi,
Does anyone know if it's possible to use regular expressions to grab all content between two words. For example....
------ This is some example text to illustrate my problem and here's another my for you. ------
I want to grab all text between the words 'some' and 'my' with the correct result being ' example text to illustrate '
The following doesn't work with either ereg or preg_match...
some([^(my)]+)my
Anyone got any ideas? Is this even possible with regular expressions?
Of course. :)
#!/usr/bin/php
<?
$string = "This is some example text to illustrate my problem and here's
another my for you.";
if (preg_match("/some(.*?)my/", $string, $m)){
print $m[1];
}
?>
--
Sandman[.net]
Paul wrote: Does anyone know if it's possible to use regular expressions to grab all content between two words. For example....
------ This is some example text to illustrate my problem and here's another my for you. ------
I want to grab all text between the words 'some' and 'my' with the correct result being ' example text to illustrate '
depends what you mean by 'word', a term which has various meanings.
1 approach to match what's between what's sometimes called orthographic
words could be:
`\bsome\b(.*?)\ bmy\b`
the same as Sandman's but with assertions that the sequences <some> and
<my> are in fact orthographic words, that is, at both ends of each are
"word" boundaries (as defined by PHP). without these assertions the
sequence <my> appearing before the word <my> would throw the match.
The following doesn't work with either ereg or preg_match...
some([^(my)]+)my
because it's a match for <some>, then one or more of any character except
'(', 'm', 'y', or ')' until the last occurrence of <my>.
character classes are not ordered, they're lists of individual characters.
--
Jock
John Dunlop wrote: Paul wrote:
some([^(my)]+)my
because it's a match for <some>, then one or more of any character except '(', 'm', 'y', or ')' until the last occurrence of <my>.
----------------------------------^^^^
meant to be 'first', the first occurrence of <my>.
--
Jock This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dimitris Georgakopuolos |
last post by:
Hello,
I have a text file that I load up to a string. The text includes
certain expression like {firstName} or {userName} that I want to match
and then replace with a new expression. However, I want to use the
text included within the brackets to do a lookup so that I can replace
the expression with the new text.
For example:
|
by: |
last post by:
Hi
I need to write one regex to read all the fields from the following lines /
file format
line 1 - some_alphanumeric,some_alphanumeric,"something,
something",numbers_hyphenatedORnot
line 2 - some_alphanumeric,some_alphanumeric,something
something,numbers_hyphenatedORnot
At first I thought this one will do
|
by: kieran |
last post by:
Hi,
I want to create a regular expression on a web form that allows the
user to input a maximum of 7 characters (these characters can be either
letters or numbers) but no full stops.
I cant seem to get this right.
Any input or simple regular expression tutorials appreciated.
|
by: Mike Zhang |
last post by:
I got stuck with regular expression problem.
What i want to do is to extract hello world if 'message' is found in the
same row.
I have gotten until //A. but somehow //B doesn't work.
<?php
$string = '<html>
<body>
<table>
<tr>
|
by: shomun |
last post by:
Hi,
I am new to regular expression stuffs. I am facing problem while implementing a reg. exp. for a textbox using regular expression validator in ASP page.
Requirement:
It will take only alphanumeric value i.e a-z,A-Z and 0-9
I am using reg. exp. ^*$
This is fine with a-z,A-Z and 0-9 checking but it also taking japanese characters
Please tell me where I am worng.
| |
by: abranches |
last post by:
Hello everyone.
I'm having a problem when extracting data from HTML with regular
expressions.
This is the source code:
You are ready in the next<br /><span id="counter_jt_minutes"
style="display: inline;"><span id="counter_jt_minutes_value">12</
span>M</span<span id="counter_jt_seconds" style="display:
inline;"><span id="counter_jt_seconds_value">48</span>S</span>
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |