Page 1 of 1

return text inbetween...

Posted: Wed Jul 19, 2006 2:29 pm
by Tsunexus
is there a way that when given a string, it will search the string and return only what is in between lets say '[bob]' and '[/bob]'

Posted: Wed Jul 19, 2006 3:20 pm
by Luke
regex

EDIT: Oops... I thought this was posted in php code... sorry! :oops:

Re: return text inbetween...

Posted: Wed Jul 19, 2006 3:44 pm
by Buddha443556
Tsunexus wrote:is there a way that when given a string, it will search the string and return only what is in between lets say '[bob]' and '[/bob]'
Regular expression (Perl) might look something like this:

Code: Select all

/\[bob\](.*?)\[\/bob\]/is
Also see preg_match().

Posted: Fri Jul 21, 2006 12:09 am
by dan.kotowski
I have a dictionary file that has entries like this:

Code: Select all

<o:ent xmlns:o="http://oup.dataformat.com/doc/OUP_DTD_Dictionary.html" sortkey="aalborg"><o:hwGrp><o:hw>Aal<o:hsb/>borg</o:hw><o:pronGrp><o:pr type="US"> |Àà&#8730;¥lÀåb&#8730;¥r(g)|</o:pr><o:pr type="US_IPA"> |Àå…ëlÀàb…îrg|</o:pr><o:pr type="US_IPA"> |Àå…îlÀàb…îrg|</o:pr><o:pr type="UK_IPA"> |Àå…îÀêlb…îÀêg|</o:pr></o:pronGrp><o:varGrp> (also<o:v> &#8730;Öl<o:hsb/>borg</o:v>) </o:varGrp></o:hwGrp><o:SB><o:sense> <o:def> an industrial city and port in northern Jutland, Denmark; pop. 155,000. </o:def></o:sense></o:SB></o:ent>
How would I get just the part after the sortkey, so that they would end up like this:

Code: Select all

aalborg
???

Posted: Fri Jul 21, 2006 12:12 am
by Burrito

Code: Select all

$pattern = "/sortkey=\"(.*?)\"/i";

Posted: Sat Jul 22, 2006 6:42 pm
by dan.kotowski
I've got this:

Code: Select all

<?php
$subject = <text from file>;
$pattern = "/sortkey=\"(.*?)\"/i";
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE, 3);
print_r($matches);
?>
But I need it to read a file that contains an entire dictionary. How would I set that up to just give me the sortlist part?

Posted: Sat Jul 22, 2006 6:43 pm
by feyd