0

I am using ruby on rails

I have

article.id = 509969989168Q000475601

I would like the output to be

article.id = 68Q000475601

basically want to get rid of all before it gets to 68Q

the numbers in front of the 68Q can be various length is there a way to remove up to "68Q"

it will always be 68Q and Q is always the only Letter is there a way to say remove all characters from 2 digits before "Q"

1
  • Your sample code is invalid. Do you mean that the value being assigned is a string? Commented Nov 12, 2014 at 6:21

3 Answers 3

2

I'd use:

article.id[/68Q.*/]

Which will return everything from 68Q to the end of the string.

Sign up to request clarification or add additional context in comments.

Comments

0
article.id.match(/68Q.+\z/)[0]

Comments

0

You can do this easily with the split method:

'68Q' + article.id.split('68Q')[1]

This splits the string into an array based on the delimiter you give it, then takes the second element of that array. For what it's worth though, @theTinMan's solution is far more elegant.

2 Comments

How does return what the OP requested?
@theTinMan woops, my mistake - I gave him the reverse. I'll fix it. Thanks for the catch!

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.