java regex search?
Hi i need to search a string with in paragraph .Here the string may be开发者_StackOverflow中文版 a java regex . How do i differentiate a regex and a ordinary string. Please give some suggestions to achieve this?
A regex is an ordinary string. For example, if you get given "a.b" should that match "axb" or not? It does if you treat it as a regular expression, it doesn't otherwise. If you want to actually search for just the value "a.b" then what would you want to be passed?
Where is the string coming from? Ideally, get that data source (whether it's the user or not) to tell you whether to use a regex or not.
Seems impossible. In fact words like I
, am
, a
and developer
are also perfectly valid regexes.
You need to tell first what patterns you'd expect to be regex patterns, then we can maybe suggest another regex pattern for this =)
Use escapes?
精彩评论