I've got a file with this in it:
[Event "Some string data"]
The data I'd like extracted is within the quotes: Some string data
I can read the file out and extract (using string positions) the data I'd
like but it would neater if I use a regular expression. Only problem is I've
never seen a working example of this type of extraction and am completely
new to PHP.
Thanks in advance 7 2251
"Reckless" <re******@nospa m.com> a écrit dans le message de news:
cj**********@ti tan.btinternet. com... I've got a file with this in it: [Event "Some string data"]
The data I'd like extracted is within the quotes: Some string data
I can read the file out and extract (using string positions) the data I'd like but it would neater if I use a regular expression. Only problem is
I've never seen a working example of this type of extraction and am completely new to PHP.
Thanks in advance
$MyString = "Event \"Some string data\"" ;
preg_match("/^Event \"([^\"]+)\"$/", $MyString, $RegArray) ;
echo $RegArray[1] ; # should display : Some string data
--
John www.realposition.com
.oO(John) $MyString = "Event \"Some string data\"" ; preg_match("/^Event \"([^\"]+)\"$/", $MyString, $RegArray) ;
JFTR: You can also use single quotes, this avoids the ugly escaping,
e.g.
preg_match('/Event "(.+)"/sU', ...);
Micha
Hi,
Thanks for the sample. Unfortunately I'm getting a null return value. This
looks to be a problem as my input line has square brackets in the source
string. If you could describe the components of the regular expression
string - this bit: ("/^Event \"([^\"]+)\"$/") perhaps I can add them in.
Thanks again!
"John" <jo**@nospam.or g> wrote in message
news:41******** *************** @news.free.fr.. . "Reckless" <re******@nospa m.com> a écrit dans le message de news: cj**********@ti tan.btinternet. com... I've got a file with this in it: [Event "Some string data"]
The data I'd like extracted is within the quotes: Some string data
I can read the file out and extract (using string positions) the data
I'd like but it would neater if I use a regular expression. Only problem is I've never seen a working example of this type of extraction and am
completely new to PHP.
Thanks in advance
$MyString = "Event \"Some string data\"" ; preg_match("/^Event \"([^\"]+)\"$/", $MyString, $RegArray) ; echo $RegArray[1] ; # should display : Some string data
-- John www.realposition.com
Reckless wrote: "John" <jo**@nospam.or g> wrote in message news:41******** *************** @news.free.fr.. .
"Reckless" <re******@nospa m.com> a écrit dans le message de news: cj**********@ titan.btinterne t.com...
I've got a file with this in it: [Event "Some string data"]
The data I'd like extracted is within the quotes: Some string data
I can read the file out and extract (using string positions) the data I'dlike but it would neater if I use a regular expression. Only problem is
I'venever seen a working example of this type of extraction and am completelynew to PHP.
$MyString = "Event \"Some string data\"" ; preg_match( "/^Event \"([^\"]+)\"$/", $MyString, $RegArray) ; echo $RegArray[1] ; # should display : Some string data Hi,
Thanks for the sample. Unfortunately I'm getting a null return value. This looks to be a problem as my input line has square brackets in the source string. If you could describe the components of the regular expression string - this bit: ("/^Event \"([^\"]+)\"$/") perhaps I can add them in.
Try something like:
preg_match('/^\[Event "(.*)(?!<(" \]))"\]/sU', $str, $matches);
That would look for
[Event "
At the beginning of a line, then match everything until it finds"
"]
Then $matches[1] would have the "data"
--
Justin Koivisto - sp**@koivi.com http://www.koivi.com
"Michael Fesser" <ne*****@gmx.ne t> wrote in message
news:d8******** *************** *********@4ax.c om... .oO(John)
$MyString = "Event \"Some string data\"" ; preg_match("/^Event \"([^\"]+)\"$/", $MyString, $RegArray) ;
JFTR: You can also use single quotes, this avoids the ugly escaping, e.g.
preg_match('/Event "(.+)"/sU', ...);
Micha
That's great thanks :)
Any recommended reading on the syntax of those pattern match strings? TIA!
"Reckless" <re******@nospa m.com> wrote in message
news:cj******** **@titan.btinte rnet.com... I've got a file with this in it: [Event "Some string data"]
The data I'd like extracted is within the quotes: Some string data
I can read the file out and extract (using string positions) the data I'd like but it would neater if I use a regular expression. Only problem is
I've never seen a working example of this type of extraction and am completely new to PHP.
Thanks in advance
$tmp = '[Event "Some string data"]';
$tmp2 = str_replace( array( '[Event "', '"]' ), '', $tmp );
.oO(Reckless) "Michael Fesser" <ne*****@gmx.ne t> wrote in message news:d8******* *************** **********@4ax. com...
preg_match('/Event "(.+)"/sU', ...);
That's great thanks :)
Any recommended reading on the syntax of those pattern match strings? TIA!
The manual? ;)
Short explanation of the pattern above:
/ opening pattern delimiter
Event " exact string match
( start of subpattern, this will be returned as result
.. any char ...
+ ... in any number, but at least one
) close subpattern
" exact string match
/ closing delimiter
s modifier: the dot . will also match on newlines
U modifier: all quantifiers (+ for example) turn to
ungreedy and match the shortest possible result (default
is greedy with matching the longest possible result)
HTH
Micha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ron Adam |
last post by:
Is it possible to match a string to regular expression pattern instead
of the other way around?
For example, instead of finding a match within a string, I want to
find out, (pass or fail), if a string is a partial match to an re.
Given an re of 'abcd and a bunch of other stuff'
This is what i'm looking for:
|
by: Kenneth McDonald |
last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate
feedback, suggestions, and criticism as I work towards finalizing the
API and feature sets. rex is a module intended to make regular expressions
easier to create and use (and in my experience as a regular expression
user, it makes them MUCH easier to create and use.)
I'm still working on formal documentation, and in any case, such
documentation isn't necessarily the...
|
by: peterbe |
last post by:
I want to match a word against a string such that 'peter' is found in
"peter bengtsson" or " hey peter," or but in "thepeter bengtsson" or
"hey peterbe," because the word has to stand on its own. The following
code works for a single word:
def createStandaloneWordRegex(word):
""" return a regular expression that can find 'peter' only if it's
written
alone (next to space, start of string, end of string, comma, etc)
but
|
by: Tom |
last post by:
I have struggled with the issue of whether or not to use Regular
Expressions for a long time now, and after implementing many text
manipulating solutions both ways, I've found that writing specialized
code instead of an RE is almost always the better solution. Here is
why....
RE's are complex. Sure it is one line of code, but it is on hell of a
line. Some of my RE remind me of the obfuscated code contest winners,
where one line of...
|
by: Kate Bieren |
last post by:
This should be easy but I am brand new to regular expressions so hopefully
someone can help me. I want to do some simple field level validation in my
app and I can do a simple test to see if the value entered in a textbox
matches a value I am expecting -
RegEx.IsMatch(textbox.text,"^LS$"). - So this will return true if my
textbox.text is "LS".
What I want to do though, is to know if the value in my textbox.text does
NOT match "LS".
| |
by: Buddy |
last post by:
Can someone please show me how to create a regular expression to do the
following
My text is set to
MyColumn{1, 100} Test
I want a regular expression that sets the text to the following
testMyColumn{1, 100}Test
Basically I want the regular expression to add the word test infront of the
|
by: Q. John Chen |
last post by:
I have Vidation Controls
First One: Simple exluce certain special characters:
say no a or b or c in the string:
*
Second One:
I required date be entered in "MM/DD/YYYY" format:
//+4 How ??
|
by: norton |
last post by:
Hello,
Does any one know how to extact the following text into 4 different
groups(namely Date, Artist, Album and Quality)?
- Artist - Album
Artist - Album
- Artist - Album
- Artist - Album-
i have try this syntax but it failed
|
by: Marc Gravell |
last post by:
In Linq, you can apparently get a meaningful body from and
expression's .ToString(); random question - does anybody know if linq
also includes a parser? It just seemed it might be a handy way to
write a safe but easy implementation (i.e. no codedom) for an
IBindingListView.Filter (by compiling to a Predicate<T>).
Anybody know if this is possible at all?
Marc
|
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:
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |