Wednesday, 15 September 2010

php - Regex Bracket Expressions exclude string -



php - Regex Bracket Expressions exclude string -

i'm trying find subtstring of string using regex. string is:

<p><a class="twitter-share-button" random stuff here </script>

i know there no script tag in random stuff made regex looks this:

<p><a class="twitter-share-button"[^</script>]*

but [^</script>] excludes characters: <, /, s, c, r, i, p, t, > how can tell regex go on searching until finds occurrence of closing script tag ?

thanks

depends on engine, can ungreedy match:

<p><a class="twitter-share-button"(.*?)</script>

the ? makes * ungreedy, match until first </script>.

php regex

No comments:

Post a Comment