[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: RegExp & File read help

Axel Etzold

6/27/2007 2:51:00 PM

Hi Don,

> I am sure there is probably a
> way to do this using an xml parsing library, but I thought it might
> be just as easy to do so with regular expressions.

Hpricot is a good choice.
>
> Where I am getting stuck is in the next code fragment, in which I am
> testing each line to see if there is a match. There should be as the
> string I used above for testing was pulled directly from one line of
> the file. Unfortunately, I get an error and no -matches.
>
> _________
> regexp = Regexp.new(/<Font-family codeSet=\"\w*\" fontId=\"\d*\">(\w*)

In the regexp, you need to escape the minus sign also, otherwise,
it is interpreted as a range of signs, i.e. f-t =['f','g',...,'t']

> regexp = Regexp.new(/<Font\-family codeSet=\"\w*\" fontId=\"\d*\">(\w*)
> <\/Font\-family>/m)

Best regards,

Axel
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/...

2 Answers

dblack

6/27/2007 3:29:00 PM

0

Don Levan

6/27/2007 4:43:00 PM

0

Hi David and Alex,

Thanks for your help. I don't have it solved yet, but you both have
cleared up the confusion.

Thanks,

Don


On Jun 27, 2007, at 11:28 AM, dblack@wobblini.net wrote:

> Hi --
>
> On Wed, 27 Jun 2007, Axel Etzold wrote:
>
>> Hi Don,
>>
>>> I am sure there is probably a
>>> way to do this using an xml parsing library, but I thought it might
>>> be just as easy to do so with regular expressions.
>>
>> Hpricot is a good choice.
>>>
>>> Where I am getting stuck is in the next code fragment, in which I am
>>> testing each line to see if there is a match. There should be as the
>>> string I used above for testing was pulled directly from one line of
>>> the file. Unfortunately, I get an error and no -matches.
>>>
>>> _________
>>> regexp = Regexp.new(/<Font-family codeSet=\"\w*\" fontId=\"\d*\">
>>> (\w*)
>>
>> In the regexp, you need to escape the minus sign also, otherwise,
>> it is interpreted as a range of signs, i.e. f-t =['f','g',...,'t']
>
> Only inside a character class. Otherwise it's just a minus sign:
>
> irb(main):017:0> Regexp.new(/a-z/).match("a")
> => nil
> irb(main):018:0> Regexp.new(/a-z/).match("literal a-z")
> => #<MatchData:0x312ce8>
>
>
> David
>
> --
> * Books:
> RAILS ROUTING (new! http://www.awprofessional.com/title/...)
> RUBY FOR RAILS (http://www.manning...)
> * Ruby/Rails training
> & consulting: Ruby Power and Light, LLC (http://www.r...)
>