Hi:
I am looking for a regex that will match a line with a single
carrot:
line = “^\n”
However, the obvious does not seem to work:
irb(main):001:0> line1 = “^\n”
=> "^\n"
irb(main):002:0> line2 = “fred”
=> "fred"
irb(main):003:0> /^^/ =~ line1
=> 0
irb(main):004:0> /^^/ =~ line2
=> 0
Using /^^/ gives an error.
What I have done to temporarily solve the problem is to use:
irb(main):012:0> /^[ ^]/ =~ line1.strip
=> 0
irb(main):011:0> /^[ ^]/ =~ line2.strip
=> nil
Does anyone know how to match ‘^’ at the beginning of a line?
···
–
Jim Freeze
Hi:
I am looking for a regex that will match a line with a single
carrot:
or caret
line = “^\n”
However, the obvious does not seem to work:
irb(main):001:0> line1 = “^\n”
=> “^\n”
irb(main):002:0> line2 = “fred”
=> “fred”
irb(main):003:0> /^^/ =~ line1
=> 0
irb(main):004:0> /^^/ =~ line2
=> 0
Using /^^/ gives an error.
This looks like an irb-ism. I get the same as you within irb, but within
real code:
$ cat x.rb
line1 = “^\n”
line2 = “fred”
p line1 =~ /^^/
p line2 =~ /^^/
$ ruby x.rb
0
nil
$ ruby -v
ruby 1.6.8 (2002-12-24) [i386-freebsd4.8]
Regards,
Brian.
···
On Mon, Jul 07, 2003 at 07:55:52AM +0900, Jim Freeze wrote:
I am looking for a regex that will match a line with a single
carrot:
(fwiw, that’s ‘caret’
Does anyone know how to match ‘^’ at the beginning of a line?
irb(main):009:0> “^foo\n” =~ //
=> 0
irb(main):010:0> “foo\n” =~ //
=> nil
irb(main):012:0> “^\n” =~ /$/
=> 0
irb(main):013:0> “^ \n” =~ /$/
=> nil
HTH
···
On Mon, Jul 07, 2003 at 07:55:52AM +0900, Jim Freeze wrote:
–
01CB B175 70D8 2E39 CA13 AEA6 3A2B 2219 31CD 5381
Dossy
(Dossy)
7 July 2003 00:03
4
You’ve gotten some other workable suggestions, but in case this one’s
interesting to you:
line =~ /^\x5e/
All in the spirit of TIMTOWTDI, of course.
– Dossy
···
On 2003.07.07, Jim Freeze jim@freeze.org wrote:
I am looking for a regex that will match a line with a single
carrot:
line = “^\n”
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
Robert
(Robert)
7 July 2003 08:36
5
The obvious solution works for me:
irb(main):011:0> line = “^\n”
“^\n”
irb(main):012:0> line =~ /^^$/ and puts “matches!”
matches!
nil
irb(main):013:0>
robert
“Jim Freeze” jim@freeze.org schrieb im Newsbeitrag
news:20030706190559.A19470@freeze.org …
···
Hi:
I am looking for a regex that will match a line with a single
carrot:
line = “^\n”
However, the obvious does not seem to work:
irb(main):001:0> line1 = “^\n”
=> “^\n”
irb(main):002:0> line2 = “fred”
=> “fred”
irb(main):003:0> /^^/ =~ line1
=> 0
irb(main):004:0> /^^/ =~ line2
=> 0
Using /^^/ gives an error.
What I have done to temporarily solve the problem is to use:
irb(main):012:0> // =~ line1.strip
=> 0
irb(main):011:0> // =~ line2.strip
=> nil
Does anyone know how to match ‘^’ at the beginning of a line?
–
Jim Freeze
% cat caret
puts (// =~ “^\n”)
% ruby caret
caret:1: invalid regular expression; empty character class: //
···
On Monday, 7 July 2003 at 10:05:22 +0900, Aredridel wrote:
line =~ /$/
–
Jim Freeze
Larkinson’s Law:
All laws are basically false.
Jim Freeze jim@freeze.org writes:
line =~ /$/
% cat caret
puts (// =~ “^\n”)
try this:
puts (“^\n” =~ //)
% ruby caret
caret:1: invalid regular expression; empty character class: //
Just remember, string goes on the left, regex goes on the right.
···
On Monday, 7 July 2003 at 10:05:22 +0900, Aredridel wrote:
–
Samuel
line =~ /$/
% cat caret
puts (// =~ “^\n”)
% ruby caret
caret:1: invalid regular expression; empty character class: //
Oh, right. I knew that. /^^/.
···
On Sun, 2003-07-06 at 19:44, Jim Freeze wrote:
On Monday, 7 July 2003 at 10:05:22 +0900, Aredridel wrote:
Which was in Jim’s original posting
···
On Mon, Jul 07, 2003 at 12:06:12PM +0900, Aredridel wrote:
On Sun, 2003-07-06 at 19:44, Jim Freeze wrote:
% ruby caret
caret:1: invalid regular expression; empty character class: //
Oh, right. I knew that. /^^/.
Actually, it doesn’t matter, but Matz prefers the regex on the left.
···
On Monday, 7 July 2003 at 11:14:29 +0900, Samuel Tesla wrote:
Jim Freeze jim@freeze.org writes:
try this:
puts (“^\n” =~ //)
% ruby caret
caret:1: invalid regular expression; empty character class: //
Just remember, string goes on the left, regex goes on the right.
–
Jim Freeze
Be a better psychiatrist and the world will beat a psychopath to your
door.
Jim Freeze jim@freeze.org writes:
Just remember, string goes on the left, regex goes on the right.
Actually, it doesn’t matter, but Matz prefers the regex on the left.
Heh. Learn something new every day.
Thanks,
Samuel
Jim Freeze jim@freeze.org writes:
Just remember, string goes on the left, regex goes on the right.
Actually, it doesn’t matter, but Matz prefers the regex on the left.
Heh. Learn something new every day.
I always wondered about that. It “reads” funny to my brain that way but I
wasn’t consulted. =D Too, it’s easy enough to do either direction, so no
worries.
I think regex-on-right is a perlism, but even in Ruby if you use =~ on two
strings, it’s the one on the right which is treated as a regex:
irb(main):003:0> “abc” =~ “b”
=> 1
irb(main):004:0> “b” =~ “abc”
=> nil
Cheers,
Brian.
···
On Tue, Jul 08, 2003 at 02:52:44AM +0900, Michael Campbell wrote:
Jim Freeze jim@freeze.org writes:
Just remember, string goes on the left, regex goes on the right.
Actually, it doesn’t matter, but Matz prefers the regex on the left.
Heh. Learn something new every day.
I always wondered about that. It “reads” funny to my brain that way but I
wasn’t consulted. =D Too, it’s easy enough to do either direction, so no
worries.
Dossy
(Dossy)
7 July 2003 18:12
15
Maybe it has to do with Matz being used to reading RTL and not LTR like
us 'merkins.
– Dossy
···
On 2003.07.08, Michael Campbell michael_s_campbell@yahoo.com wrote:
Jim Freeze jim@freeze.org writes:
Just remember, string goes on the left, regex goes on the right.
Actually, it doesn’t matter, but Matz prefers the regex on the left.
Heh. Learn something new every day.
I always wondered about that. It “reads” funny to my brain that way but I
wasn’t consulted. =D Too, it’s easy enough to do either direction, so no
worries.
–
Dossy Shiobara mail: dossy@panoptic.com
Panoptic Computer Network web: http://www.panoptic.com/
“He realized the fastest way to change is to laugh at your own
folly – then you can let go and quickly move on.” (p. 70)
Brian Candler B.Candler@pobox.com writes:
I think regex-on-right is a perlism, but even in Ruby if you use =~ on two
strings, it’s the one on the right which is treated as a regex:
That’s certainly where I picked it up.