如何从字符串中提取“程序名称”。该字符串将如下所示:
%O0033(SUB RAD MSD 50R III)G91G1X-6.4Z-2.F500 G3I6.4Z-8。G3I6.4 G3R3.2X6.4F500 G91G0Z5。G91G1X-10.4 G3I10.4 G3R5.2X10.4 G90G0Z2。M99%
程序名称为(SUB RAD MSD 50R III)。将结果存储在另一个字符串中就可以了。我正在学习功能强大的工具,所以对您答案的任何解释将不胜感激。
以下正则表达式提取括号之间的所有内容:
PS> $prog = [regex]::match($s,'\(([^\)]+)\)').Groups[1].Value
PS> $prog
SUB RAD MSD 50R III
Explanation (created with RegexBuddy)
Match the character '(' literally «\(»
Match the regular expression below and capture its match into backreference number 1 «([^\)]+)»
Match any character that is NOT a ) character «[^\)]+»
Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
Match the character ')' literally «\)»
检查以下链接:
感谢您的回答。您能解释一下吗,或者我如何学习正则表达式?任何推荐的好网站。