I would like a regular expression to match given a partial or camel cased string. For example, if the search set contains the string ‘MyPossibleResultString’ I want to be able to match it with the likes of the following:
- MyPossibleResultString
- MPRS
- MPRString
- MyPosResStr
- M
I’d also like to include wildcard matching, e.g.:
- MyP*RString
- *PosResString
- My*String
If it’s not clear what I mean, the only example I can think of is Eclipse’s ‘Open Type’ dialog which is pretty much the exact behaviour I’m looking for. I’m not too up on the use of regexes, so I’m not sure if it matters if I’m looking for a solution in Java.
Ok so I can’t really see why you would need the wildcard feature if you can already support the matching described in the first example. This is what I put together. Given a query string query, you use a regular expression to create a regular expression:
For example the query
MyPosResStrwill become the regex:You then use this regex for your matching using the
Matcher.findmethod to get something like this:This will return the first match to your camel case query in the string str.
EDIT: I have added a line to handle wildcards since in my tired stupor I didn’t appreciate the need for them