# Regexp help

**URL:** <https://rubytalk.org/t/regexp-help/58565>\
**Category:** ruby-talk\
**Created:** [18 May 2010 10:39 UTC](https://rubytalk.org/t/regexp-help/58565 "2010-05-18T10:39:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrea\_Carmisciano](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@Andrea\_Carmisciano](https://rubytalk.org/u/Andrea_Carmisciano)\
**Post date:** [18 May 2010 10:39 UTC](https://rubytalk.org/t/regexp-help/58565/1 "2010-05-18T10:39:47Z")

</div>

Hi, I'm newbie to ruby, but I try searching a lot for my problem...

I need to extract from an enormous text file, in natural language, for  
two separated element in the same line and put them in a new file.

Example:  
IIS - IPSIASAR L. DA VINCI (XN\_\_\_\_01) - Responsabile: ENRICO FLAIANO  
VIA MONTE S. ROCCO, 15 PINETA SIGNORINI - 67100 L'AQUILA (AQ) - tel.  
0862 22112 - fax. 0862 22300 email : [ipias\_aq@yahoo.it](mailto:ipias_aq@yahoo.it) -  
url:[http://www.istitutoleonardodavinciaq.191.it](http://www.istitutoleonardodavinciaq.191.it)

I need to extract the code (XN\_\_\_\_01) and the relative email  
"ipias\_aq@yahoo.it", put them in a CSV file or a sort of.

May I do this in ruby?

Thank's very much for any help and so sorry for my bad english...

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Luis1](https://avatars.discourse-cdn.com/v4/letter/l/91b2a8/32.png) [@Luis1](https://rubytalk.org/u/Luis1)\
**Post date:** [18 May 2010 11:37 UTC](https://rubytalk.org/t/regexp-help/58565/2 "2010-05-18T11:37:28Z")

</div>

You can do it using a capture group:  
[http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp](http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp)  
and examples here: [Regex Tutorial - Parentheses for Grouping and Capturing](http://www.regular-expressions.info/brackets.html)

> **···**
>
> On Tue, May 18, 2010 at 7:39 AM, Andrea Carmisciano \<andrea.carmisciano@gmail.com\> wrote:
> 
> > Hi, I'm newbie to ruby, but I try searching a lot for my problem...
> > 
> > I need to extract from an enormous text file, in natural language, for  
> > two separated element in the same line and put them in a new file.
> > 
> > Example:  
> > IIS - IPSIASAR L. DA VINCI (XN\_\_\_\_01) - Responsabile: ENRICO FLAIANO  
> > VIA MONTE S. ROCCO, 15 PINETA SIGNORINI - 67100 L'AQUILA (AQ) - tel.  
> > 0862 22112 - fax. 0862 22300 email : ipias\_aq@yahoo.it -  
> > url:[http://www.istitutoleonardodavinciaq.191.it](http://www.istitutoleonardodavinciaq.191.it)
> > 
> > I need to extract the code (XN\_\_\_\_01) and the relative email  
> > "ipias\_aq@yahoo.it", put them in a CSV file or a sort of.
> > 
> > May I do this in ruby?
> 
> --  
> Luis Parravicini  
> [http://ktulu.com.ar/blog/](http://ktulu.com.ar/blog/)

---

<div class="post-metadata">

**Author:** ![Andrea\_Carmisciano](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@Andrea\_Carmisciano](https://rubytalk.org/u/Andrea_Carmisciano)\
**Post date:** [18 May 2010 12:36 UTC](https://rubytalk.org/t/regexp-help/58565/3 "2010-05-18T12:36:31Z")

</div>

Luis Parravicini wrote:

> **···**
>
> > On Tue, May 18, 2010 at 7:39 AM, Andrea Carmisciano \> \<andrea.carmisciano@gmail.com\> wrote:
> > 
> > > I need to extract the code (XN\_\_\_\_01) and the relative email  
> > > "ipias\_aq@yahoo.it", put them in a CSV file or a sort of.
> > > 
> > > May I do this in ruby?
> > 
> > You can do it using a capture group:  
> > [Ruby Syntax](http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp)  
> > and examples here: [Regex Tutorial - Parentheses for Grouping and Capturing](http://www.regular-expressions.info/brackets.html)
> 
> Thank you, but 'couse I'm quiet stupid, can you write me a pseudo-coded  
> example? For the regex part, not the file open/write part.  
> Thank's again!  
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Spec\_Ex](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Spec\_Ex](https://rubytalk.org/u/Spec_Ex)\
**Post date:** [18 May 2010 17:40 UTC](https://rubytalk.org/t/regexp-help/58565/4 "2010-05-18T17:40:56Z")

</div>

Andrea Carmisciano wrote:

> Luis Parravicini wrote:
> 
> > > I need to extract the code (XN\_\_\_\_01) and the relative email  
> > > "ipias\_aq@yahoo.it", put them in a CSV file or a sort of.
> > > 
> > > May I do this in ruby?
> > 
> > You can do it using a capture group:  
> > [Ruby Syntax](http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp)  
> > and examples here: [Regex Tutorial - Parentheses for Grouping and Capturing](http://www.regular-expressions.info/brackets.html)
> 
> Thank you, but 'couse I'm quiet stupid, can you write me a pseudo-coded  
> example? For the regex part, not the file open/write part.  
> Thank's again!

Maybe this can help:

> **[Rubular](https://rubular.com/)**
>
> Ruby-based regular expression editor/tester

> **···**
>
> > > On Tue, May 18, 2010 at 7:39 AM, Andrea Carmisciano \>\> \<andrea.carmisciano@gmail.com\> wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [19 May 2010 14:23 UTC](https://rubytalk.org/t/regexp-help/58565/5 "2010-05-19T14:23:26Z")

</div>

It's a bit difficult to guess which parts of your line are stable and  
which not, i.e. how to build the regexp. Can you post, say 5,  
different lines so we can recognize the pattern?

Kind regards

robert

> **···**
>
> 2010/5/18 Andrea Carmisciano \<andrea.carmisciano@gmail.com\>:
> 
> > Luis Parravicini wrote:
> > 
> > > On Tue, May 18, 2010 at 7:39 AM, Andrea Carmisciano \>\> \<andrea.carmisciano@gmail.com\> wrote:
> > > 
> > > > I need to extract the code (XN\_\_\_\_01) and the relative email  
> > > > "ipias\_aq@yahoo.it", put them in a CSV file or a sort of.
> > > > 
> > > > May I do this in ruby?
> > > 
> > > You can do it using a capture group:  
> > > [Ruby Syntax](http://ruby-doc.org/docs/ruby-doc-bundle/Manual/man-1.4/syntax.html#regexp)  
> > > and examples here: [Regex Tutorial - Parentheses for Grouping and Capturing](http://www.regular-expressions.info/brackets.html)
> > 
> > Thank you, but 'couse I'm quiet stupid, can you write me a pseudo-coded  
> > example? For the regex part, not the file open/write part.
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)
