|
Posted by Karin Jensen on 10/11/70 11:24
Hi
I am writing in PHP and trying to work with regular expressions
on records in a multilanguage database. I understand regexp basics,
but have bitten off more than I can chew here and really need help.
The problem is to do with generating all strings that match a
pattern defined in terms of brackets and slashes. Here, brackets
mean that something is optional and slashes are used to show
alternatives.
In the examples below, all the matches I need to generate are
shown below the original string.
Here are some simple brackets:
aardappel(en)
aardappel
aardappelen
homard ( la) bordelaise
homard bordelaise
homard la bordelaise
And brackets used in combination with slashes:
croquant(e)/(s)
croquant
croquante
croquants
croquantes
agrio/a/(s)
agrio
agria
agrios
agrias
Words can also be bracketed:
crale(s) (froide(s))
crale
crales
crale froide
crales froides
crale froides (even though these last
crales froide two aren't proper French)
And slashes used for whole word alternatives:
jablecn zvin/trdl
jablecn zvin
jablecn trdl
cuerpo, con/de
cuerpo, con
cuerpo, de
douillon(s)/douillen(s)
douillon
douillons
douillen
douillens
Maybe the expression would have to decide on a whole word
substitution rather than a single letter - e.g "cuerpo, con/de"
isn't "cuerpo, cde" - if the "slashed" term is more than a single
letter?
I think I can see how to generate a set of rules based on the
above, but I have no idea how to implement the logic of them using
preg functions.
Help!
And thanks in advance...
Karin
Navigation:
[Reply to this message]
|