Hi i need to search a string with in paragraph .Here the string may be a java regex . How do i differentiate a regex and a ordinary string. Please give some suggestions to achieve this?
+4
A:
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.
Jon Skeet
2009-11-11 12:36:14
actually the string is from user ..the user may or may not know regex pattern searching
Sidharth
2009-11-11 12:52:21
Well only the user knows whether they expect "a.b" to match "axb" then. The user *has* to give you that information - e.g. by having a checkbox saying "Treat this as a regular expression", defaulting to false.
Jon Skeet
2009-11-11 12:57:46
yes this is a good solution
Sidharth
2009-11-11 13:09:53
Who is the user? What are you actually trying to achieve? Please clarify your question and the problem you want to solve.
Pascal Thivent
2009-11-11 12:54:21
+2
A:
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 =)
BalusC
2009-11-11 12:40:16