0

ok so i am pulling my hair out here trying to figure out why php doesnt want to work right with this reg expression

what i am looking for

{blog:name_of_blog}

what i have
preg_match_all('\{blog:[A-Za-z0-9_]+\}', $replaced_content, $matches, PREG_SET_ORDER);


this is the error it is out putting

Warning: preg_match_all() [function.preg-match-all]: Delimiter must not be alphanumeric or backslash in


where i tested it
http://www.regexpal.com/?flags=&regex=\{blog%3A[A-Za-z0-9_]%2B\}&input={blog%3Ablog_name_here}

please help. ive started to understand reg expressions more but this error just does make sense to me

thanks in advance

4
Contributors
7
Replies
9
Views
6 Years
Discussion Span
Last Post by itisnot_me
1

Try this.

<?
	$replaced_content = " abcs is here {blog:vibhadevit} mnop dsgdh 3535 {blog:computer} after blog content";
	preg_match_all('/{blog:[A-Za-z0-9_]+}/', $replaced_content, $matches, PREG_SET_ORDER);
	echo '<pre>';
	print_r($matches);
?>
0

@viraaa: huh?

Interesting why is it that you use the / after the }?

Another thing is what if I wanted to do something like this {blog:name_of_blog/tag:tag_name} and later on I could grab one or both, if both exist, for later. The example is is to put them into variables I would guess.

0

Interesting why is it that you use the / after the }?

The / before and after is called the delimiter, which was missing in your regex. The delimiter can be any character you want, as long as the regex starts and ends with it. The reason for having one, is that you can put additional options after the closing delimiter (case sensitivity for example).

0

thanks thats good to know. btw i was able to find a work around for the variables i was talking about.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.