1

Need parse a lot of text files and replace any quoted strings containing cyrillic symbols. They are may contains new lines, non-alphabetic characters and special symbols (for example '$' or escaped quote). Can anyone help with regex?

From comments:

for example php code

function hello($word) {
    $word2 = "ха-ха!";
    echo "Привет, $word $word2\n"; 
}
hello('Мир'); 

I need match "ха-ха!", "Привет, $word $word2\n" and 'Мир'

4

2 回答 2

2

这应该有效:

str = 'The cat is under the "таблица"'
regex = /"\p{Cyrillic}+.*?\.?"/ui

str.match(regex){|s| do_stuff_with_each_matching s} 

# or...

str.gsub!(regex){|s| method_that_translates_russian s}

在http://rubular.com/r/0Mwbfinjvp现场查看。
http://www.ruby-doc.org/core-1.9.3/Regexp.html

于 2013-01-14T13:58:33.037 回答
0

".*[^a-zA-Z\d]+.*"匹配任何包含至少一个非字母数字字符的引用字符序列。

即它匹配"aa$bb"并且"a1$b1"

它不匹配"aabb"a$b

希望这是您想要的(添加所需的转义)。

于 2013-01-14T13:32:04.660 回答