假设我有一段如下:
Hello,
Test-12.2.1 we are testing this
Test-13.12.1 we are testing this
Test
我只需要抓住以Test-
开头的第一个单词。所以我会抓住Test-12.2.1
对上述案例进行处理。
答案 0 :(得分:2)
str = "Hello,
Test-12.2.1 we are testing this
Test-13.12.1 we are testing this
Test"
然后您可以执行以下任一操作
str[/Test-\S+/] #=> Test-12.2.1
str.slice(/Test-\S+/) #=> Test-12.2.1