由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - implement a simple regular expression match? (转载)
相关主题
leetcode regular expression match的问题leetcode里最弄不明白的两道题
what is regular expression's meaning?regular expression match的greedy解法
Wildcard Matching 和 Regular Expression Matching 区别是什么请问大牛们关于Regular expression matching
如果面试遇到 regular expression match 或者 wildcard matching之类的leetcode这两题不是完全一样吗?
Regular expression matching 在什么输入下时间复杂度是O(2^n)?[面笔试分享] Phone Interview Skills(转) very helpful!!!
面试遇到了Regular Expression Matching时间复杂度是多少?大家看看这几道亚麻面试题怎么做?
老书还是得读呐Java String concatenation
请教一个面试题,在大量URL中找一个有wildcard的patternregular expression (转载)
相关话题的讨论汇总
话题: match话题: expression话题: regular话题: implement话题: simple
进入JobHunting版参与讨论
1 (共1页)
g*********s
发帖数: 1782
1
【 以下文字转载自 Programming 讨论区 】
发信人: gandjmitbbs (Nothing), 信区: Programming
标 题: implement a simple regular expression match?
发信站: BBS 未名空间站 (Tue Jan 25 02:30:51 2011, 美东)
the regular expression only includes a-z, '*', and '.'
support:
1. "x*", aka 0 or more continuous 'x'
2. ".", aka wildcard matching any letter.
it seems back-trace is inevitable because of the following ambiguity:
match("b", "b*.") == true;
match("b", "b*") == true;
l*****a
发帖数: 14598
2
关于正则表达式匹配,我的做法如下。
将输入pattern 转化成状态数组。
比方说 ab*d
initial state=s[0]
f(s[0],a)=s[1]
f(s[1],b)=s[2]
f(s[2],b)=s[2]
f(s[1],d)=s[3]
f(s[2],d)=s[3]
end state=s[3]
对于希望进行匹配的字符串,逐个分析当前字符,查上面的hash_map or matrix
judge whether it can start from s[start] and move to s[end]
if so,it match.
otherwise,doesn't match

【在 g*********s 的大作中提到】
: 【 以下文字转载自 Programming 讨论区 】
: 发信人: gandjmitbbs (Nothing), 信区: Programming
: 标 题: implement a simple regular expression match?
: 发信站: BBS 未名空间站 (Tue Jan 25 02:30:51 2011, 美东)
: the regular expression only includes a-z, '*', and '.'
: support:
: 1. "x*", aka 0 or more continuous 'x'
: 2. ".", aka wildcard matching any letter.
: it seems back-trace is inevitable because of the following ambiguity:
: match("b", "b*.") == true;

g*********s
发帖数: 1782
3
what if input is "bb" and pattern "b*b"?

【在 l*****a 的大作中提到】
: 关于正则表达式匹配,我的做法如下。
: 将输入pattern 转化成状态数组。
: 比方说 ab*d
: initial state=s[0]
: f(s[0],a)=s[1]
: f(s[1],b)=s[2]
: f(s[2],b)=s[2]
: f(s[1],d)=s[3]
: f(s[2],d)=s[3]
: end state=s[3]

l*****a
发帖数: 14598
4
这个问题问得很好
f(s[0],'b')=s[0] //for b* we can use this (*=1..n)
f(s[0],'b')=s[1] //for b*,*=0,we can use this
对于同一状态,相同输入,可能有不同结果
就各种情况试一遍好了。

【在 g*********s 的大作中提到】
: what if input is "bb" and pattern "b*b"?
g*********s
发帖数: 1782
5
i don't see any simple way to do this.
what u described here is just a finite automata. u still need to eliminate
the non-determinism of nfa.

【在 l*****a 的大作中提到】
: 这个问题问得很好
: f(s[0],'b')=s[0] //for b* we can use this (*=1..n)
: f(s[0],'b')=s[1] //for b*,*=0,we can use this
: 对于同一状态,相同输入,可能有不同结果
: 就各种情况试一遍好了。

l*****a
发帖数: 14598
6
basically you should use b*b instead of b*

eliminate

【在 g*********s 的大作中提到】
: i don't see any simple way to do this.
: what u described here is just a finite automata. u still need to eliminate
: the non-determinism of nfa.

1 (共1页)
进入JobHunting版参与讨论
相关主题
regular expression (转载)Regular expression matching 在什么输入下时间复杂度是O(2^n)?
regular expression面试遇到了Regular Expression Matching时间复杂度是多少?
Google onsite老书还是得读呐
leetcode 上面的Regular Expression Matching请教一个面试题,在大量URL中找一个有wildcard的pattern
leetcode regular expression match的问题leetcode里最弄不明白的两道题
what is regular expression's meaning?regular expression match的greedy解法
Wildcard Matching 和 Regular Expression Matching 区别是什么请问大牛们关于Regular expression matching
如果面试遇到 regular expression match 或者 wildcard matching之类的leetcode这两题不是完全一样吗?
相关话题的讨论汇总
话题: match话题: expression话题: regular话题: implement话题: simple