Forum Moderators: coopster

Message Too Old, No Replies

Small regexp question

         

Blooish

1:34 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



How do i find a portion of text until a word occurs.
Example string: "this is a simple text"
regexp: "/this(^(text)*)text/"
this should return " is a simple " but it doesnt.
Please help me.

cameraman

4:48 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



#this(.*)text#

Blooish

5:54 pm on Oct 28, 2008 (gmt 0)

10+ Year Member



Thanks for your reply but things were a little bit more complicated. The solution in my case was to use the lookahead assertion.

andrewsmd

5:59 pm on Oct 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



if you don't need a regex you can use this
<?PHP
//the string you are searching for
$searchPattern = "this";

//the string we are searching
$string = "this is a simple text";

//this is the position where the string
//starts we then add the length of the
//pattern to get where it ends
$position = (strpos($string, $searchPattern) + strlen($searchPattern));

//set a substring to the position where
//the search pattern ends
$result = (substr($string, $position));

echo($result);
?>