正则表达式使用pdf-reader解析字符串

时间:2021-05-16 16:50:25

Well, I have to parse this line in Ruby on Rails

好吧,我必须在Ruby on Rails中解析这一行

TD(AQ-163W-1B2V) Tj0.00 -13.52 TD(AQ-180W-7BV) Tj0.00 -13.48 TD(AW-48HE-1AV) Tj0.00 -13.52 TD(AW-48HE-8AV) Tj0.00 -13.48 TD(AW-49H-7EV) Tj0.00 -13.52 TD(AW-80D-1AV) Tj0.00 -13.48 TD(AW-80D-2AV)

I need a regular expression to store only data inside TD, without parenthesis. In this case it will be:

我需要一个正则表达式来仅存储TD内的数据,不带括号。在这种情况下,它将是:

["AQ-163W-1B2V", "AQ-180W-7BV", "AW-48HE-1AV", etc.]

Any idea? Thanks!

任何想法?谢谢!

1 个解决方案

#1


1  

You may use string.scan

你可以使用string.scan

> s = "TD(AQ-163W-1B2V) Tj0.00 -13.52 TD(AQ-180W-7BV) Tj0.00 -13.48 TD(AW-48HE-1AV)"
> s.scan(/\(([^()]+)\)/)
=> [["AQ-163W-1B2V"], ["AQ-180W-7BV"], ["AW-48HE-1AV"]]
> s.scan(/(?<=\()[^()]+(?=\))/)
=> ["AQ-163W-1B2V", "AQ-180W-7BV", "AW-48HE-1AV"]

#1


1  

You may use string.scan

你可以使用string.scan

> s = "TD(AQ-163W-1B2V) Tj0.00 -13.52 TD(AQ-180W-7BV) Tj0.00 -13.48 TD(AW-48HE-1AV)"
> s.scan(/\(([^()]+)\)/)
=> [["AQ-163W-1B2V"], ["AQ-180W-7BV"], ["AW-48HE-1AV"]]
> s.scan(/(?<=\()[^()]+(?=\))/)
=> ["AQ-163W-1B2V", "AQ-180W-7BV", "AW-48HE-1AV"]