1

The user inputs the following info into a textarea:

  Member[0] [U:1:189360279]  team = 0
  Member[1] [U:1:189331590]  team = 0
  Member[2] [U:1:52453166]  team = 0
  Member[3] [U:1:129146865]  team = 0
  Member[4] [U:1:187520208]  team = 0
  Member[5] [U:1:25945591]  team = 1
  Member[6] [U:1:188594831]  team = 1
  Member[7] [U:1:145357907]  team = 1
  Member[8] [U:1:116190211]  team = 1
  Member[9] [U:1:183457922]  team = 1

I want to extract only the long number that comes after [U:1: (i.e. 189360279), for each line, and then make an array out of all of the numbers that are extracted.

I tried some different expressions on http://www.rubular.com/ but am coming up short, I am not very familiar with regex.

1
  • To capture all the numbers, you can use: \[U:1:(\d+)] Commented Aug 16, 2014 at 10:48

2 Answers 2

3

It's very simple: \[U:\d:(\d+)\]. And then:

text.scan(/\[U:\d:(\d+)\]/).map { |i| i.first.to_i }
Sign up to request clarification or add additional context in comments.

Comments

2

To extract the long number use:

(?!\[U:\d+:)(?<=:)\d+(?=\])

This matches the long number in capturing group 0.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.