| Code: |
| preg_match('/<div style=\"visibility:hidden\">(.+?)<\/div>/',$a,$captured_elements); |
if I want to make this multi-line capable...what can I do?
| Code: |
| preg_match('/<div style=\"visibility:hidden\">(.+?)<\/div>/',$a,$captured_elements); |
| Code: |
|
preg_match('/<div\s+style="visibility:hidden">(.+?)<\/div>/mi',$a,$captured_elements); |
| MrBlueSky wrote: | ||
Here you go. Also case-insensitive.
|
| Code: |
|
preg_match('/<div\s+style="visibility:hidden">(.+?)<\/div>/si',$a,$captured_elements); |
| Code: |
| preg_match('/\<div\s+style\="visibility\:hidden"\>(.+?)\<\/div\>/si', $a, $captured_elements); |
| Mgccl wrote: |
|
I don't think it works... |
| gorn wrote: | ||
(Change the m to an s) The single line/multiline thing is confusing. But in this case you want all the text to be treated as if it's on a single line (ie \n is just a normal character). |
| bladesage wrote: |
| Well, for one, you place a lot of unescaped special characters in there...
The symbols <>=: are special pattern characters with special meanings that alter the pattern. |
| MrBlueSky wrote: | ||||||||
My mistake. What gorn says:
There are no characters in his pattern that should be escaped, he even escaped 'too much'. <>=: are not special characters in regular expressions. |
| php.net wrote: |
| The special regular expression characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : |
| Code: |
|
"(?<=pattern)" A zero-width positive look-behind assertion. For example, "/(?<=\t)\w+/" matches a word that follows a tab, without including the tab in $&. Works only for fixed-width look-behind. "(?<!pattern)" A zero-width negative look-behind assertion. For example "/(?<!bar)foo/" matches any occurrence of "foo" that does not follow "bar". Works only for fixed-width look-behind. ... "(?>pattern)" WARNING: This extended regular expression feature is consid- ered highly experimental, and may be changed or deleted with- out notice. An "independent" subexpression, one which matches the sub- string that a standalone "pattern" would match if anchored at the given position, and it matches nothing other than this substring. This construct is useful for optimizations of what would otherwise be "eternal" matches, because it will not backtrack (see "Backtracking"). It may also be useful in places where the "grab all you can, and do not give anything back" semantic is desirable. ... "(?:pattern)" "(?imsx-imsx:pattern)" This is for clustering, not capturing; it groups subexpres- sions like "()", but doesn't make backreferences as "()" does. So @fields = split(/\b(?:a|b|c)\b/) is like @fields = split(/\b(a|b|c)\b/) |
| bladesage wrote: | ||||||||||||
I trust the people at the official PHP website myself. And I did have problems before by not escaping the above symbols. So, all things considered, I'd say that these are special characters. |
| Programming Perl wrote: |
|
For all their power and expressivity, patterns in Perl recognize the same 12 traditional metacharacters (the Dirty Dozen, as it were) found in many other regular expression packages: \ | ( ) [ { ^ $ * + ? . |
| php.net wrote: |
|
Meta-characters The power of regular expressions comes from the ability to include alternatives and repetitions in the pattern. These are encoded in the pattern by the use of meta-characters, which do not stand for themselves but instead are interpreted in some special way. There are two different sets of meta-characters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized in square brackets. Outside square brackets, the meta-characters are as follows: \ general escape character with several uses ^ assert start of subject (or line, in multiline mode) $ assert end of subject (or line, in multiline mode) . match any character except newline (by default) [ start character class definition ] end character class definition | start of alternative branch ( start subpattern ) end subpattern ? extends the meaning of (, also 0 or 1 quantifier, also quantifier minimizer * 0 or more quantifier + 1 or more quantifier { start min/max quantifier } end min/max quantifier |
| Code: |
|
/<.*?>/ |
| gorn wrote: | ||
(Change the m to an s) The single line/multiline thing is confusing. But in this case you want all the text to be treated as if it's on a single line (ie \n is just a normal character). |