编程介的小学生 2017-03-07 11:13 采纳率: 20.5%
浏览 699
已采纳

Advanced Regular Expression

Given a paragraph and several regular expressions, your task is to find the first match of each regular expression. If multiple matches exist, you must output the longest one.
The regular expression can contain some meta-characters described below:

  • Matches the preceding character/meta-character zero or more times.
  • Matches the preceding character/meta-character one or more times. ? Matches the preceding character/meta-character zero or one time. . Matches any single character. [xyz] A character set. Matches any characters within the brackets. [^xyz] A negative character set. Matches any characters NOT within brackets. \d Matches a digit character. \D Matches a non-digit character. \a Matches a alpha character. \A Matches a non-alpha character. \n Matches a new-line character. (ASCII 10) \s Matches any white-space character including space, tab and new-line. \S Matches any non-white-space character. \t Matches a tab character. (ASCII 9) \w Matches an alphanumeric character (including "_") \W Matches a non-alphanumeric character. * Matches "*". + Matches "+". \? Matches "?". . Matches ".". [ Matches "[". ] Matches "]". \ Matches "\".

Note:
1. [ ] always appear in pairs and will not be nested.
2. The character set within [ ] will not be empty.
3. Meta-characters can not be used within [ ].

Input

The first line of input contains an integer n, the number of test cases. Each test case begins with an integer L, and the following L lines give the paragraph. The next line contains an integer m, with the following m lines containing a regular expression each.

You can assume that each paragraph contains no more than 100,000 characters and each regular expression has no more than 100 characters.

Output

For each test case, first print the case number on a single line, then print the match for each regular expression. If no match is found, print "No match is found". Print a blank line after each test case.

Always print a '\n' after each match unless the match ends with a '\n' itself. Print a line with 44 dashes after each match.

Empty match is NOT valid.

Some Examples:
m.n matches "man", "men", "min" but not "moon".
Te+st matches "test", "teest", "teeeest" etc. BUT NOT "tst".
Te*st matches "test", "teest", "teeeest" etc. AND "tst".
[aeiou] matches every lowercase vowel.
[,.?] matches a literal ",", "." or "?".
[^^] matches any character except "^".

Sample Input

2
1
Hello world!
2
He.*d!
He*d!
1
Sunny Cup
1
Sunny Cup

Sample Output

Case #1:

Hello world!

No match is found

Case #2:

Sunny Cup

  • 写回答

2条回答 默认 最新

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图