# Reg :regular expression

**URL:** <https://www.ruby-forum.com/t/reg-regular-expression/113654>\
**Category:** Rails\
**Created:** [September 3, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654 "2007-09-03T15:34:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 3, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/1 "2007-09-03T15:34:12Z")

</div>

Hi,

Iam facing problem in excluding new line in reular expression…(/n)  
eg: shiva.grp\nhi da so it should exclude \n .if any one knows help me

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 3, 2007, 8:14pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/2 "2007-09-03T20:14:39Z")

</div>

You’ll have to make the regexp multline with the /m option (i.e. /foo/  
m) or it won’t match across newlines.

Rein

On Sep 3, 12:36 pm, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 4, 2007, 8:38am UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/3 "2007-09-04T08:38:24Z")

</div>

Rein H. wrote:

> You’ll have to make the regexp multline with the /m option (i.e. /foo/  
> m) or it won’t match across newlines.
> 
> Rein
> 
> On Sep 3, 12:36 pm, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks for your reply  
this is my regular expression  
my source is this

mygroup.grp  
hi how r u  
iam fine

str=~/^([a-zA-Z]{1}[a-zA-Z0-9]{0,}.([a-zA-Z]{1,}))\s(.\*)$/m

if i put this regular expression it is not matching

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 4, 2007, 9:27am UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/4 "2007-09-04T09:27:36Z")

</div>

I need to understand, you don’t want anything after new line?

or you want to remove \n and use your regular expression?

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 3, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/5 "2007-09-03T19:36:38Z")

</div>

Shiva K. wrote:

> Hi,
> 
> Iam facing problem in excluding new line in reular expression…(/n)  
> eg: shiva.grp\nhi da so it should exclude \n .if any one knows help me

Exclude you don’t want it?

[^\n]

something like that or ?

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 4, 2007, 10:18am UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/6 "2007-09-04T10:18:01Z")

</div>

Jamal S. wrote:

> I need to understand, you don’t want anything after new line?
> 
> or you want to remove \n and use your regular expression?

its like this

eg: shiva.grp hi how r u  
eg: shiva.grp  
hi how r u

both this format should accept

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 4, 2007, 4:33pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/7 "2007-09-04T16:33:41Z")

</div>

Hi Shivan,  
I tried with this regex, it worked for both the example you mentioned.

reg = /^[a-zA-Z]+.[a-zA-Z]+[a-zA-Z]+[\s]\*$/

str = two example values you specified.

str =~ reg -----\> 0(output)

On Sep 4, 1:18 pm, Shiva K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 5, 2007, 6:39am UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/8 "2007-09-05T06:39:05Z")

</div>

Matthew R. wrote:

> raghukumar wrote:
> 
> > Hi Shivan,  
> > I tried with this regex, it worked for both the example you mentioned.
> > 
> > reg = /^[a-zA-Z]+.[a-zA-Z]+[a-zA-Z]+[\s]\*$/
> > 
> > str = two example values you specified.
> > 
> > str =~ reg -----\> 0(output)
> > 
> > On Sep 4, 1:18 pm, Shiva K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> irb(main):001:0\> regexp = /^([a-zA-Z]\w\*.([a-zA-Z]+))\s(._)$/m  
> =\> /^([a-zA-Z]\w_.([a-zA-Z]+))\s(.\*)$/m  
> irb(main):002:0\> “mygroup.grp\nhi how r u\niam fine” =~ regexp  
> =\> 0  
> irb(main):003:0\> $1  
> =\> “mygroup.grp”  
> irb(main):004:0\> $2  
> =\> “grp”  
> irb(main):005:0\> $3  
> =\> “hi how r u\niam fine”

thnaks man for your help

(str=~/^([a-zA-Z]{1}[a-zA-Z0-9]{0,}.([a-zA-Z]{1,}))$/i)

in the above expression it should not allow new line but it allowing  
inside

pls help me…iam poor in regular expression

---

<div class="post-metadata">

**Author:** ![shiva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/85e7bf/32.png) [@shiva](https://www.ruby-forum.com/u/shiva)\
**Post date:** [September 4, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/reg-regular-expression/113654/9 "2007-09-04T17:44:12Z")

</div>

raghukumar wrote:

> Hi Shivan,  
> I tried with this regex, it worked for both the example you mentioned.
> 
> reg = /^[a-zA-Z]+.[a-zA-Z]+[a-zA-Z]+[\s]\*$/
> 
> str = two example values you specified.
> 
> str =~ reg -----\> 0(output)
> 
> On Sep 4, 1:18 pm, Shiva K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

irb(main):001:0\> regexp = /^([a-zA-Z]\w\*.([a-zA-Z]+))\s(._)$/m  
=\> /^([a-zA-Z]\w_.([a-zA-Z]+))\s(.\*)$/m  
irb(main):002:0\> “mygroup.grp\nhi how r u\niam fine” =~ regexp  
=\> 0  
irb(main):003:0\> $1  
=\> “mygroup.grp”  
irb(main):004:0\> $2  
=\> “grp”  
irb(main):005:0\> $3  
=\> “hi how r u\niam fine”
