From: Kyle Schmitt Date: 2007-07-11T05:45:05+09:00 Subject: Re: Help: Efficient regular expression I love regex, so it hurts me to say it, there are other ways of solving this ;) for instance: string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash" number = string.split[1] program=string.split.last now regexes! string = "root 14051 14033 3 08:39 pts/2 00:00:00 /bin/bash" number=string[/[0-9]+/] program=string[/[a-z\/]+$/] You know you can get values out of an array with the [] operator. Well you can get strings out of strings that same way, and it works with regexes! string[/[0-9]+/] will return the first match of 1 or more numbers Here's the magic use [ ] inside of a regular expression to create your own groups. Individual characters in there are included in the group, and ranges may be included using the -. so a-b is abcdefghijklmnopqrstuvwxyz. The + afterwards means 1 or more times. What if you want _exactly 5 consecutive numbers? use the {} string[/[0-9]{5}/] ranges also work here string[/[0-9]{3-5}/] would match 3, 4 or 5 digit numbers and string[/[a-z\/]+$/] will match a text string containing the forward slash at the end. The $ is a special char to represent the end of a line, and since / is a special char itself, it needed to be escaped with a \. BUT it could even be easier. the [] groups, can be negative! /[^a]*/ would match any string that did not have an a in it /[^ ]*/ would match any string that did not have a space in it...soo string[/[^ ]+$/] would be a good way to get the last bit.