[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regular expressions on strings with multiple newlines

Adam Akhtar

9/13/2008 6:46:00 AM

im banging my head against a wall with this. Im sure theres an easy way
to solve this.

Say i have this string

"xxx cfghyrfhyuijhcdf xxxx"

and i want all letters between the x`s

i would write something like this

/x*?(.*?)x*/

but if there are some unknown number of newlines seperating those
letters like so

"xxx cfg\nhyrfh\nyuij\nhcdf xxxx"

that reg fails

I tried


/x*?(.|\n)*?x*/

but match[1] can return a "" if it reaches a newline first rather than
the full sequence of letters and newlines (i dont mind having the
newlines returned)


I know i can simply gsub all hte newlines out of the string first but
just wondering if theres a way round this with a regexp
--
Posted via http://www.ruby-....

2 Answers

Sebastian Hungerecker

9/13/2008 7:52:00 AM

0

Adam Akhtar wrote:
> /x*?(.*?)x*/
>
> but if there are some unknown number of newlines seperating those
> letters like so
>
> "xxx cfg\nhyrfh\nyuij\nhcdf xxxx"
>
> that reg fails

>> "xxx cfg\nhyrfh\nyuij\nhcdf xxxx" =~ /x*?(.*?)x*/m
=> 0
Notice the m.

HTH,
Sebastian
--
NP: Dismember - Europa Burns
Jabber: sepp2k@jabber.org
ICQ: 205544826

Adam Akhtar

9/13/2008 7:55:00 AM

0

ahhhhhh i forgot about that option... i knew it was a simple answer and
i was just overlooking it. Thank you for helping me with that.

--
Posted via http://www.ruby-....