I'm clearly missing something! I have a log analysis application that
is written in Ruby and which uses REs to decide how to process log
records.
I entered a pattern into one of my rules and it always failed to match
so I fired up irb and set about reducing the pattern to something
minimal:
[rful011@pateke selms-svn]$ irb
irb(main):001:0> a = 'NT AUTHORITY\SYSTEM'
=> "NT AUTHORITY\\SYSTEM"
irb(main):004:0> a =~ /AUTHORITY/
=> 3
irb(main):005:0> a =~ /NT AUTHORITY/
=> 0
irb(main):006:0> a =~ / AUTHORITY/
=> 2
irb(main):007:0> a =~ /^NT /
=> 0
irb(main):008:0> a =~ /NT /
=> 0
irb(main):009:0> a =~ /NT/
=> 0
irb(main):010:0> a =~ /N/
=> 0
irb(main):011:0> a =~ /T/
=> 1
Is the '\' in the string upsetting things?
Cheers and thanks,
Russell
···
--
Posted via http://www.ruby-forum.com/.
Russell,
I'm clearly missing something! I have a log analysis
application that is written in Ruby and which uses
REs to decide how to process log records.
I entered a pattern into one of my rules and it always
failed to match so I fired up irb and set about
reducing the pattern to something minimal:
[rful011@pateke selms-svn]$ irb
irb(main):001:0> a = 'NT AUTHORITY\SYSTEM'
=> "NT AUTHORITY\\SYSTEM"
irb(main):004:0> a =~ /AUTHORITY/
=> 3
irb(main):005:0> a =~ /NT AUTHORITY/
=> 0
irb(main):006:0> a =~ / AUTHORITY/
=> 2
irb(main):007:0> a =~ /^NT /
=> 0
irb(main):008:0> a =~ /NT /
=> 0
irb(main):009:0> a =~ /NT/
=> 0
irb(main):010:0> a =~ /N/
=> 0
irb(main):011:0> a =~ /T/
=> 1
Is the '\' in the string upsetting things?
No, you are just misinterpreting the results.
irb(main):001:0> a = 'NT AUTHORITY\SYSTEM'
=> "NT AUTHORITY\\SYSTEM"
irb(main):002:0> a =~ /N/
=> 0
irb(main):003:0> a =~ /X/
=> nil
Zero is a valid string index, nil is not.
- Warren Brown
Russell Fulton wrote:
I'm clearly missing something! I have a log analysis application that
is written in Ruby and which uses REs to decide how to process log
records.
I entered a pattern into one of my rules and it always failed to match
so I fired up irb and set about reducing the pattern to something
minimal:
[rful011@pateke selms-svn]$ irb
irb(main):001:0> a = 'NT AUTHORITY\SYSTEM'
=> "NT AUTHORITY\\SYSTEM"
irb(main):004:0> a =~ /AUTHORITY/
=> 3
irb(main):005:0> a =~ /NT AUTHORITY/
=> 0
irb(main):006:0> a =~ / AUTHORITY/
=> 2
irb(main):007:0> a =~ /^NT /
=> 0
irb(main):008:0> a =~ /NT /
=> 0
irb(main):009:0> a =~ /NT/
=> 0
irb(main):010:0> a =~ /N/
=> 0
irb(main):011:0> a =~ /T/
=> 1
I'm not sure what you're expecting here - all these patterns are matching. Have you got a failing pattern?
···
--
Alex
Warren Brown wrote:
Zero is a valid string index, nil is not.
Thanks Warren! Like I said I was clearly missing something. I blame my
perl heritage
Russell
···
--
Posted via http://www.ruby-forum.com/\.