C
C
ChemAli2013-11-13 15:09:19
Regular Expressions
ChemAli, 2013-11-13 15:09:19

How to parse and normalize a freely populated text field (php+regexp)?

There is a freely populated field “experience”, now it contains values ​​like “it doesn’t matter”, “from 1 year old”, “3-5 years old”, “up to 21 years old” and so on. The challenge is to reduce this entire set to two integer fields "experience from" and "experience to", parsing the existing values ​​and covering most cases.

Am I going to do the right thing if I make a set of regular expressions and, applying them sequentially to the field, will try to rip out values ​​from there? Is this a normal move in this situation? Are there smarter ways?

Don't laugh, I'm a noob.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2013-11-13
@ChemAli

if there is a large selection of values ​​​​of this field (there is a ready-made base available), then it is quite possible to try to cover this with regular expressions. But I wouldn't use them consistently. It's best to sort expressions from longest to shortest and return the result from the first successful match.

M
Maxim Ivanushchik, 2013-11-13
@makis

Perhaps it's better to make a slider instead of a text field to select the values ​​"from" and "to"?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question