Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Matching set of paragraph tags with string inside.

by moritz (Cardinal)
on Feb 08, 2008 at 20:54 UTC ( [id://667066]=note: print w/replies, xml ) Need Help??


in reply to Matching set of paragraph tags with string inside.

In the second example you're trying to match <p></p> directly, with an additional assertion. Try /<p>(?=.*?\[tab\]).*?<\/p>/ instead. But that doesn't check if the [tab] occurs before the </p>, so don'T try to mess with lookarounds but use your first pattern.

Update: OK, that doesn't fix your real problem. I'll have to think a bit more about it. In this simple case you can just use [^<>] instead of a dot everywhere between <p> and </p>.

The old truth that HTML shouldn't be parsed with regexes still holds.

Replies are listed 'Best First'.
Re^2: Matching set of paragraph tags with string inside.
by the_0ne (Pilgrim) on Feb 08, 2008 at 21:02 UTC
    My problem with the first match is it matches too much...
    original: "<p>no tabs here</p><p>column 1[tab]column 2</p><p>no tabs here</p>" result of first regex: no tabs here</p><p>column 1[tab]column 2
    What I want it to match is...
    column 1[tab]column 2
    Since that is the set of para's with the string [tab].
      My first shot was too fast, here's a working solution:
      my $contents = "<p>no tabs here</p><p>column 1[tab]column 2</p><p>no t +abs here</p>"; if ($contents =~ m{(<p>[^<>]*\[tab\][^<>]*</p>)} ){ print "Matched '$1'\n;"; }
Re^2: Matching set of paragraph tags with string inside.
by the_0ne (Pilgrim) on Feb 08, 2008 at 21:05 UTC

    I understand your concern of parsing html with regexes, but this string will never be a full set of html. It will have some html (of course with the para's) but using a parser would be overkill for this situation.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://667066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-16 20:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found