regex problem

  • Thread starter Thread starter reiks
  • Start date Start date
R

reiks

My requirement is to match the word-'text="Description"'
in the below line



text(band=header alignment="0" text="Description"
border="0" color="8388608" x="206" y="0" height="64"
width="338" font.face="Arial" font.height="-10"
font.weight="700" font.family="2" font.pitch="2"
font.charset="0" background.mode="1"
background.color="536870912" )

I've used the following expression
"text=\"(.+)\"" . But it's not giving me the correct match

Could anyone help em out?


thanks in advance,
reiks
 
By non-greedy, Luc means:

text=\"(.+?)\"

The problem that you're having is that quantifiers like + and * try to match
as long a string as possible by default, so it's matching the " near the end
of the string. This is called "greedy matching". The two ways around it are
either to use a negated character class (as Luc suggests) that prevents
skipping any ", or by adding the non-greedy "?" modifier to the quantifier.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
Luc E. Mistiaen said:
non greedy search or "text=\"([^"]+)\""

reiks said:
My requirement is to match the word-'text="Description"'
in the below line



text(band=header alignment="0" text="Description"
border="0" color="8388608" x="206" y="0" height="64"
width="338" font.face="Arial" font.height="-10"
font.weight="700" font.family="2" font.pitch="2"
font.charset="0" background.mode="1"
background.color="536870912" )

I've used the following expression
"text=\"(.+)\"" . But it's not giving me the correct match

Could anyone help em out?


thanks in advance,
reiks
 
Back
Top