# Gsub and reg expressions

**URL:** <https://www.ruby-forum.com/t/gsub-and-reg-expressions/153408>\
**Category:** IT\
**Created:** [November 16, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/gsub-and-reg-expressions/153408 "2008-11-16T18:33:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [November 16, 2008, 6:33pm UTC](https://www.ruby-forum.com/t/gsub-and-reg-expressions/153408/1 "2008-11-16T18:33:25Z")

</div>

After considerable time racking my brains on this one I am unsure on  
where to go.

I am trying to replace some text with a the string ‘local’

I am reading some data from an event description, therefore using a  
regular expression to get only the data i want which is ‘Logon Type: 2’

This works fine but when I add gsub to the expression in an attempt to  
replace ‘Logon Type: 2’ with “local” I get the following error:

C:/Documents and Settings/sc/Desktop/stutest.rb:116:in `gsub’: wrong  
argumen  
t type Array (expected Regexp) (TypeError)

Also my code

#{event.description.gsub([/Logon Type:\t2/], ‘Local’)}")

Thanks in advance

---

<div class="post-metadata">

**Author:** ![sclarke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b19c9b/32.png) [@sclarke](https://www.ruby-forum.com/u/sclarke)\
**Post date:** [November 17, 2008, 7:15pm UTC](https://www.ruby-forum.com/t/gsub-and-reg-expressions/153408/2 "2008-11-17T19:15:34Z")

</div>

Stuart C. wrote:

> After considerable time racking my brains on this one I am unsure on  
> where to go.
> 
> I am trying to replace some text with a the string ‘local’
> 
> I am reading some data from an event description, therefore using a  
> regular expression to get only the data i want which is ‘Logon Type: 2’
> 
> This works fine but when I add gsub to the expression in an attempt to  
> replace ‘Logon Type: 2’ with “local” I get the following error:
> 
> C:/Documents and Settings/sc/Desktop/stutest.rb:116:in `gsub’: wrong  
> argumen  
> t type Array (expected Regexp) (TypeError)
> 
> Also my code
> 
> #{event.description.gsub([/Logon Type:\t2/], ‘Local’)}")

mmm

[/Logon Type:\t2/] IS an Array

/Logon Type:\t2/ is a Regexp

take off the square brackets 😉  
and you have:

("#{event.description.gsub(/Logon Type:\t2/, ‘Local’)}")

> Thanks in advance

Not at all

Duilio R.
