0

I have the following string in PHP:

<p> [#form id=1]</p>

What is the pattern for getting it? I tried this:

/\<p\>\s\[\#.+?.\]\s\<\/p\>/

But it does not work. Any idea?

Francis Gilbert
  • 3,382
  • 2
  • 22
  • 27
José Carlos
  • 1,005
  • 16
  • 29
  • To match that chunk, to match the id attribute, to match that specific pattern or arbitrary chars within `p` tags? – alex Jun 08 '11 at 13:13
  • 1
    Ahem: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – johnsyweb Jun 08 '11 at 13:16
  • 1
    Is it possible to use a parser instead? You shouldn't really use regex to match html: http://www.codinghorror.com/blog/2005/04/parsing-beyond-regex.html – Francis Gilbert Jun 08 '11 at 13:21

3 Answers3

2
/\<p\>\s*\[\#.+?.\]\s*\<\/p\>/

You don't have space after ] , but regexp test for it

SergeS
  • 11,533
  • 3
  • 29
  • 35
2

In the string there is nothing between ] and <

<p> [#form id=1]</p>
               ^^

But in your regex you've a \s (one whitespace character) between ] and <. Either drop the \s if you are sure there will be nothing between or change it to \s* if there can be any number of whitespace characters.

codaddict
  • 445,704
  • 82
  • 492
  • 529
1

You don't have a space after the ] sign,

Have a try with :

~<p> \[#.+\]</p>~
Toto
  • 89,455
  • 62
  • 89
  • 125