Results 1 to 5 of 5
Jul 3, 2006, 16:25 #1
see your knowledge on "ereg" (help)
i have a string="aaa bbb ccc ddd eee ddd fff"
and i want to grab a sub string which starts with "bbb" and ends with the first "ddd" not the second or more if there any.
so i want to grab this="bbb ccc ddd"
but the problem is there are two "ddd"s in my string
i used this regexp=
echo"$out"; (that "" includes your limitations of "aaa" and "ddd" which i want it to be)
but this code sees a sub string which ends with the last "ddd" of the main string so my output is becomes like this=bbb ccc ddd eee ddd
but i want "bbb ccc ddd"
finally i want my substring to start with "bbb", and end with the first "ddd" coming after "bbb"
pleaseeeeeeeeeee help me about this, this regexp will also help many people
Jul 3, 2006, 16:37 #2
- Join Date
- May 2006
- Ventura, CA
- 0 Post(s)
- 0 Thread(s)
well, you want in that case:
from what you're saying. Also it's $out for the first match, $out is the entire matched string.
Jul 3, 2006, 17:59 #3
i don't use the posix functions (ereg, eregi, etc) so I don't know if they support ungreedy matching or not. There is really no good reason to use them from what I know of them, as the perl-compatible regex functions are faster and have more features
here's how you would do that using preg_match() :
Jul 4, 2006, 03:42 #4
yes i tried preg_match at first but that command does not grab a substring which contains linebreaks.
and i couldnt make it grab. if there is way for preg_match i really prefer that!
Jul 4, 2006, 07:19 #5
if you want the dot (.) to match line breaks, just add the 's' modifier: