Optional characters in Flex expression - lex

I'm trying to make a flex expression which identifies money, to 2 decimal places. This isn't for any practical use, I'm just messing around with flex and trying to learn it.
I am looking for money in this format: $100.00 or $100000.00 or -$100.00
This is not much of an issue, I can use this expression:
[$][0-9]+[.][0-9]+
I can also add to it to detect negative numbers:
-?[$][0-9]+[.][0-9]+
My problem is, with how I have it $100.00 would be identified as expected, but $100.000000 would also be identified as a money token. How do I ensure that there are only 2 decimals shown?
Is there any way to tell Flex to limit the amount of characters in an expression? I could do something like this;
-?[$][0-9]+[.][0-9][0-9]
but this seems like a bad solution. What if I wanted 10 decimal places? Tagging lots of [0-9]'s on the end seems like a bad idea.

Related

The word function have a problem with decimal values

I'm having a problem with the following code.I would like to display the amount of money of people with the $ sign. In the interface there is a monitor that shows the actual money of an agent, but with the function word it shows to me all the decimal places possible (I inserted 2, but seems it doesn't care). The code is inside the monitor's reporter.
Thanks in advance.
word "$" sum [money] of people
When you use the function word, you are no longer displaying a number but rather a string. Because of that, the notion of decimal places no longer applies because you are looking at text.
That means you need to change the number of decimals the number has before you turn it into a string. Precision is a primitive that allows you to manipulate the number of decimals. Combining that with your code gives the following:
word "$ " precision sum [money] of people 2
Displayed below with brackets to make it a bit more clear what happens when.
(word "$ " (precision (sum [money] of people) 2) )

Typeahead Bloodhound - Filter

My index contains the word dog how can i also find this entry if i type dogs? I would find all parts of the word 'dogs','dog','do' to a min length of 2 or 3 chars
I'm not an expert on Bloodhound, but what you're talking about here is called stemming, and it seems like the kind of thing that you could do using the datumTokenizer and the queryTokenizer.
There are stemmers for most languages of varying quality, but I think the one most people are using for English these days is the Snowball Stemmer. There are a number of implementations in JavaScript floating around.
In general for things to work properly you'll want to stem both the uer's query and the results.

Barcode4j UPCA scancode with leading zero

I'm trying to add a barcode to a report using Jasper Reports in UPCA format. My scancodes are strings, but Barcode4j expects a 12 digit Integer. I can convert this to an Integer, but if there is a leading zero, it is lost, and thus my scancode is now 1 digit too short.
So, how can I use the UPCA format with scancodes that have a leading 0 and keep the leading 0?
Barbecue seems to have the same issues, so I don't imagine using it as opposed to Barcode4j will solve this issue.
Well, it all came down to my test data. Using random numbers is what was causing it to fail. When I looked up UPCA examples and used those, then it worked fine. I didn't have to parse it as an Integer either.

Iphone work out if string is a UK Postcode

In my app before I send a string off I need to work out if the text entered in the textbox is a UK Postcode. I don't have the regex ability to work that out for myself and after searching around I can't seem to work it out! Just wondered if anyone has done a similar thing in the past?
Or if anyone can point me in the right direction I would be most appreciative!
Tom
Wikipedia has a good section about this. Basically the answer depends on what sort of pathological cases you want to handle. For example:
An alternative short regular expression from BS7666 Schema is:
[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][ABD-HJLNP-UW-Z]{2}
The above expressions fail to exclude many non-existent area codes (such as A, AA, Z and ZY).
Basically, read that section of Wikipedia thoroughly and decide what you need.
for post codes without spaces (e.g. SE19QZ) I use: (its not failed me yet ;-) )
^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2})
if spaces (e.g. SE1 9QZ) , then:
^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$
You can match most post codes with this regex:
/[A-Z]{1,2}[0-9]{1,2}\s?[0-9]{1,2}[A-Z]{1,2}/i
Which means... A-Z one or two times ({1,2}) followed by 0-9 1 or two times, followed by a space \s optionally ? followed by 0-9 one or two times, followed by A-Z one or two times.
This will match some false positives, as I can make up post codes like ZZ00 00ZZ, but to accurately match all post codes, the only way is to buy post code data from the post office - which is quite expensive. You could also download free post code databases, but they do not have 100% coverage.
Hope this helps.
Wikipedia has some regexes for UK Postcodes: http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation

How can I compare international phone numbers in Perl?

Are there any modules that can help me compare phone numbers for equality?
For example, the following three numbers are equivalent (when dialling from the UK)
+44 (0)181 1234123
00441811234123
0181 1234123
Is there a perl module that can tell me this?
The closest I can see on CPAN is Number::Phone which is an active project, and supports UK Phone numbers. It should work for the specific example you give. A few countries are supported.
If you've got phone numbers for other countries things could get more difficult due to local formatting idiosyncrasies.
Supposing that the code you need doesn't exist, and you have to write it yourself, there are two basic operations that you need to do:
Apply context. This is where you take the location of the dialing phone into account. If the call isn't international, you supply the country code; if the call isn't long-distance, you provide an area code, etc. This requires some rules per-locale, of course.
Normalize. Remove meaningless spaces and punctuation, convert the international dialing prefix ("011" in NANPA, "00" in most of the rest of the world, but occasionally many weirder things) to the standard "+".
After completing those two steps properly, all inputs that are actually equivalent numbers should give identical output strings.