4

Does anyone know of a library (preferably php) or algorithm for auto-generating regex's from some common descriptions?

For example, have a form with the possible options of:

 - Length (=x, between x & y, etc)
  - Starts with
  - Ends with
  - Character(s) x(yz) at index i
  - Specify one or more alternative behavior based on the above
  - And so on..

The idea is that for certain data entities in a system, you'll be able to go to a form and set this criteria for a data field. Afterward, any time that data field for that type of data entity is entered, it will be validated against the regex.

This seems like it could grow into a complex problem though, so I'm not expecting anyone to solve it as a whole. Any suggestions are much appreciated.

4

1 回答 1

2

Would simple globs be enough? For globs it's just a matter of replacing * with .* and adding ^ and $. Or may be Excel-style patterns? It should not be too hard to write a regexp generator for simple rules like this...

My point is, adjust your requirements to simplify the code, and then may be add more features as needed.

于 2008-09-05T17:34:06.927 回答