regex

B

boris bass

the following is the text string i am trying to match


bgColor=#ffffff

and i constructed the following regular expr


while ( $content =~ /=\s*[^"]#\w{6}[^"]/ )


and it doesnt seem to be working


I am actually trying to match from the equal sign and rightward, i.e.
match equal sign followed by zero or more whitespaces followed by the
pound sign followed by exactly six alphanumerics and NOT QUOTED -

NOT QUOTED is the whole point of a match

any suggestions appriciated
 
T

Tad McClellan

boris bass said:
the following is the text string i am trying to match

bgColor=#ffffff

I am actually trying to match from the equal sign and rightward, i.e.
match equal sign followed by zero or more whitespaces followed by the
pound sign followed by exactly six alphanumerics and NOT QUOTED -

NOT QUOTED is the whole point of a match


/=\s*#\w{6}/
or
/=\s*#\w{6}(?!")/
 
J

John W. Krahn

boris said:
the following is the text string i am trying to match

bgColor=#ffffff

and i constructed the following regular expr

while ( $content =~ /=\s*[^"]#\w{6}[^"]/ )

and it doesnt seem to be working

I am actually trying to match from the equal sign and rightward, i.e.
match equal sign followed by zero or more whitespaces followed by the
pound sign followed by exactly six alphanumerics and NOT QUOTED -

NOT QUOTED is the whole point of a match

any suggestions appriciated


$ perl -le'
for ( q/bgColor=#ffffff/, q/bgColor="#ffffff"/, q/ bgColor = #ffffff /, q/ bgColor = "#ffffff" / ) {
print if /=\s*(?<!")#[[:xdigit:]]{6}(?!")/;
}
'
bgColor=#ffffff
bgColor = #ffffff



John
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (boris bass) wrote in @posting.google.com:
the following is the text string i am trying to match


bgColor=#ffffff

and i constructed the following regular expr


while ( $content =~ /=\s*[^"]#\w{6}[^"]/ )

The problem is that

[^"]

matches "exactly one character that is not a quote". So it requires one
non-quote character between the optional whitespace and the # symbol.

You really don't need the [^"] business. If you are matching on \w{6},
it'll match six word characters; any quotes would cause the match to fail
anyhow.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP0q5xmPeouIeTNHoEQKxWgCg49tuMBDtc2jBGlGlAq6k4EgPlFkAn1Gk
iXyn5MLSm3qvcw0y/ShqKMsy
=fIVV
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top