I am using a JSON to validate data from a series of invoices. First of all, I have removed all the spaces from the data, and then I validate the fields according to the definition found in a JSON. It has served me perfectly, but now I find myself with a small problem:
If you wanted to validate the text:
Total electricity €54.60
I did it this way:
"regexp": {
"productType": "Electricidad",
"electricityTotal": "Totalelectricidad([\\d\\,\\.]+)€"
}
But I want to validate invoices in Basque, Catalan...etc. I don't know how to make it filter the following text:
Argindarra guztira / Total electricity €54.60
My problem is how to make it include the slash "/" and take it as part of the string, since it is the only thing that changes in the expression.
I want the character to be recognized "/"
as part of the string, for example:
"regexp": {
"productType": "Electricidad",
"electricityTotal": "Argindarraguztira/Totalelectricidad([\\d\\,\\.]+)€"
}
In this case it gives me an error, because I need to include something in the expression so that it admits the "/".
Your expression may work but may fail.
For example, with your part of
[\\d\\,\\.]+
you are telling him to take 1 or more of those elements but not all combinations are valid.That's why I would put:
which searches for numbers followed by the possibility of a semicolon and more numbers.
Ex:
5555€
,55.55€
,5,55555€
55,.55€
,55,€
,.55€
To accept the possibility of having another language in front of "Total electricity" you can put an optional group
(?:Argindarra guztira \/ )?
leaving everything:If you would like to add other languages you can add more using the
"|"
(or) operator and the other languages.