编程介的小学生 2017-02-22 14:40 采纳率: 20.5%
浏览 909
已采纳

Pattern Matching Using Regular Expression

A regular expression is a string which contains some normal characters and some meta characters. The meta characters include,
. means any character

[c1-c2] means any character between c1 and c2 (c1 and c2 are two characters)

[^c1-c2] means any character not between c1 and c2 (c1 and c2 are two characters)

  • means the character before it can occur any times

  • means the character before it can occur any times but at least one times

\ means any character follow should be treated as normal character
You are to write a program to find the leftmost substring of a given string, so that the substring can match a given regular expression. If there are many substrings of the given string can match the regular expression, and the left positions of these substrings are same, we prefer the longest one.

Input

Every two lines of the input is a pattern-matching problem. The first line is a regular expression, and the second line is the string to be matched. Any line will be no more than 80 character. A line with only an "end" will terminate the input.

Output

For each matching problem, you should give an answer in one line. This line contains the string to be matched, but the leftmost substring that can match the regular expression should be bracketed. If no substring matches the regular expression, print the input string.

Sample Input

.*
asdf
f.*d.
sefdfsde
[0-9]+
asd345dsf
[^*-*]
asdffasd
b[a-z]*r[s-u]*
abcdefghijklmnopqrstuvwxyz
[T-F]
dfkgjf
end

Sample Output

(asdf)
se(fdfsde)
asd(345)dsf
(a)sdffasd
a(bcdefghijklmnopqrstu)vwxyz
dfkgjf

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-02-28 21:23
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog