From: Chad Perrin Date: 2011-07-25T01:30:09+09:00 Subject: Re: Help with Regex --Q68bSM7Ycu6FN28Q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jul 25, 2011 at 12:26:54AM +0900, Phillip Gawlowski wrote: > On Sun, Jul 24, 2011 at 5:11 PM, Gregory Ma wrot= e: > > I need help with a Regular Expression, I need to split the text on "- " > > on get the first element. >=20 > Try String#split: >=20 > >> ary =3D "I want this - not that.".split(" - ") > =3D> ["I want this", "not that."] > >> ary[0] > =3D> "I want this" =2E . . and if you want to split it into only two elements even if there are multiple instance of the split substring, use the optional limit argument: >> ary =3D "I want this - not that - nor the other.".split(' - ', 2) =3D> ["I want this", "not that - nor the other."] >> ary[0] =3D> "I want this" >> ary[1] =3D> "not that - nor the other." --=20 Chad Perrin [ original content licensed OWL: http://owl.apotheon.org ] --Q68bSM7Ycu6FN28Q Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (FreeBSD) iEYEARECAAYFAk4sRJwACgkQ9mn/Pj01uKXjUgCdFyXIv40hq727sUa4cCxb7xYj eHUAmwVmI87XgKffMlblD4sUkOrxHJMu =Kc6/ -----END PGP SIGNATURE----- --Q68bSM7Ycu6FN28Q--