pcre - Regex match with negative look ahead and non greedy -


source string

<html name="abc:///testers/something.txt" in="abc/testers/something.txt" loci="123" sap="abcdefgh="/><html name="abc:///needed.txt" src="abc/needed.txt" location="123" sap="rtyghu"/><html name="abc:///testers/testers3/another.txt" in="abc/testers/testers3/another.txt" loci="123" sap="jhkiopjhg"/><html name="abc:///onemore.txt" src="abc/onemore.txt" location="123" sap="dfrtyu"/> 

how match section starting <html name=" not followed (needed) or (onemore) , ending />

so in string there should 2 matches are

<html name="abc:///testers/something.txt" in="abc/testers/something.txt" loci="123" sap="abcdefgh="/> <html name="abc:///testers/testers3/another.txt" in="abc/testers/testers3/another.txt" loci="123" sap="jhkiopjhg"/> 

i tried - <html name=(?!(needed|onemore)).*?"\/>

it doesnt work confused non greedy , negative lookahead stuffs.

what need use repetition quantifier in addition putting restriction on should give traversing:

<html\s+name="(?![^"]*(?:needed|onemore))[^>]*> 

live demo


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -