I need a statement that gives a certain amount depending on the field value:
If x is in the range between 10 and 20 then the answer is 15 if not then it should go to identical statement with a different range.
I cant seem to get the first part working, this is what I got so far:
{=IF(AND(x>10,x<20)"yes","no")}
Try:
{=INT((X-1)/10)=1 \# "'Yes';;'No'"}
Alternatively:
{=AND(Val>10,Val<20) \# "'Yes';;'No'"}
To see how to do a wide range of other calculations in Word, check out my Microsoft Word Field Maths Tutorial, at:
https://www.msofficeforums.com/word/38720-microsoft-word-field-maths-tutorial.html
or:
http://www.gmayor.com/downloads.htm#Third_party
You really don't need all that circumlocution. For example:
{IF«field»> 300 125 {IF«field»> 200 100 {IF«field»> 100 75 0}}}
Related
I apologize in advance, this might be a repeat question. However, I just spent the two last hours over stackoverflow, and can't seem to find a solution.
I want to use grepl to detect rows that begin with a digit, that's what I tried to use but It didn't give me the rigt answer:
grep.numeric=as.data.frame(grepl("^[:digit:]",df_mod$name))
I guess that the problem is from the regular expression "^[:digit:]", but I couldn't figure it out.
UPDATE
My dataframe looks like this, It's huge, but below is an example:
ID mark name
1 whatever name product
2 whatever 10 product
3 whatever 250 product
4 another_mark other product
I want to detect products which their names begin with a number.
UPDATE 2
applying grep.numeric=grepl("^[[:digit:]]",df_mod$name) on the example below give me the right answer which is:
grep.numeric
[1] FALSE TRUE TRUE FALSE
But, what drive me crazy is when I pply this fuction to my real dataframe:
grep.numeric=grepl("^[[:digit:]]",df_mod[217,]$nom)
give me this result:
grep.numeric
[1] FALSE
But actually, what I have is this :
df_mod[217,]$nom
[1] 100 lipo 30 gélules
Please help me.
Apparently, some of your values have leading spaces, so you could either modify your regex to (or something similar)
grepl("^\\s*[[:digit:]]", df_mod$name)
Or use the built in trimws function
grepl("^[[:digit:]]", trimws(df_mod$name))
i'm trying to make a regex for this condition:
6 numbers max
finish always with 00
lowest input 5000
These should match:
5000
11100
699900
999900
These should not match:
900
4900
12345
999999
1230000
I browsed through the site, but without success.
I'm not very good at regex - could somebody please help?
Use the following
^([5-9]\d|[1-9]\d{2,3})00$
I think you mean 5000 or above:
^([5-9]\d|[1-9]\d{2,3})00$
See a live demo.
I think that this should match all of them. We deal with the 4 digit case separately:
^([1-9][0-9]{2,3}00)|([5-9][0-9]00)$
^[5-9][0-9]{1,3}00
So has to start with a digit between 5 and 9 ^[5-9]
Then can have any number between 0-9 1, 2 or 3 times and must end with 00
Look at the following demo
^([5-9]\d{1,3}|[1-4]\d{2,3})00$
I'm trying to find a valid price validation for my needs..
Valid input format (xxx means no maximum length - 0000 means 4 decimal places at maximum):
15,0000
15.0000
150.0000
150,0000
xxxxxxxxxxxx.0000
xxxxxxxxxxxx,0000
15,00
15,1
15.00
15.1
Invalid input format (basically everything that starts by 0):
01.0000
01.00
01
My regular expression so far: ^\$?[1-9][1-9,]*[0-9]\.?[0-9]{0,2}$
Edit 1: Changed my regex for this one: ^\$?[1-9]*[1-9]((\,)|(\.))?[0-9]{0,4}$ but now I need to be able to add 150000000 and it only allows me 150000
EDIT: just saw that you updated the question and added 0 as a valid input. I'll see if I can add that.
How about:
^([1-9].*[,\.][0-9]*)$
This will work on the examples above.
But be careful with input like 15x,001
See it in action
Okay this one seems okay to me
^[^0]\d+(\.|\,)?[0-9]{0,4}$
checked here http://rubular.com/r/97Ra9VS9h4
and yes one more thing if you want to check for one digit numbers also like 1,2 etc
then you can just replace the + with * like this ^[^0]\d*(\.|\,)?[0-9]{0,4}$
What about this one:
^\$?[1-9][0-9]*(,|\.)[0-9]{1,4}$
The first regex makes sure the price doesnt starts with a zero.
Then all numbers are allowed, zero or more numbers.
Then there must be a comma or a point.
Finaly all numbers are allowed, max count is four and minimum one
^[1-9][0-9]*([.,][0-9]{1,4})?$
Hi I am using this to generate ranges on a switch: http://code.google.com/p/klish/wiki/subcommands
I have set the pattern to be 0-255. This works fine
<PTYPE name="MAX_LEARN_ADDR"
method="integer"
pattern="0..255"
/>
This correctly only accepts 0-255 and stops things like * $ £ saying they are invalid. However - causes an error. I tried:
^([01]?[0-9]?[0-9]|2[0-4][0-9]|25[0-5])$
Same thing happens.
sample legal input:
switch(config-if)# switchport port-security maximum 3
%INFO: port-security maximum is 3, up to 3 DYNAMIC addresses will be learned
Sample illegal input:
switch(config-if)# switchport port-security maximum *
Syntax error: Illegal parameter
However:
switch(config-if)# switchport port-security maximum -
gives a python trace because the - is not being caught as an invalid parameter and is getting passed to the function.
^([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])$ would be what you need
Why don't you try using this instead for the pattern you are supposed to allow?
Edit 2 Alright, this should do the trick!
^(25[0-5]|[2][0-4]\d|[1]\d\d|[1-9]\d|\d)$
this regex might do the work for you.
^25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d$
The first part: 25[0-5] allows numbers between 250 to 255
The second part: 2[0-4]\d allows numbers between 200 to 249
The third part: 1\d\d allows numbers from 100 to 199
and the last part: [1-9]?\d allows numbers from 0 to 99, and makes sure that 00 or 01 do not get accepted, but 0, 1, etc do.
The answer is that there is an issue in klish if the range starts with 0.
What is the RegEx for value Range from 1- 365
Try this:
^(?:[1-9]\d?|[12]\d{2}|3[0-5]\d|36[0-5])$
The start anchor ^ and end anchor
$ are to match the whole input and
not just part of it.
(? ) is for grouping.
| is for alternation
[1-9]\d? matches 1 to 99
[12]\d{2} matches 100 to 299
3[0-5]\d matches 300 to 359
36[0-5] matches 360 to 365
You would have to list the possible combinations 1-9, 10-99, 100-299, 300-359, 360-365:
^([1-9]\d?|[12]\d\d|3[0-5]\d|36[0-5])$
Not really a good fit for regex, but if you insist:
^(?:36[0-5]|3[0-5][0-9]|[12][0-9][0-9]|[1-9][0-9]|[1-9])$
This is not allowing leading zeroes. If you wish to allow those, let me know.
The expression above can be shortened a little to
^(?:36[0-5]|3[0-5]\d|[12]\d{2}|[1-9]\d?)$
but I find the first solution to be a bit more readable. YMMV.
A general solution for matching the numbers from 1 to XYZ
^(?!0)(?!\d{4}$)(?![X+1-9]\d{2}$)(?!X[Y+1-9]\d$)(?!XY[Z+1-9]$)\d+$
Notes:
If any of X, Y or Z are 9 that will make X+1 etc. be 10. If that happens the regex part that would require using the 10 should be left out.
This can be extended to numbers with more or less digits following the same principles.
It does not allow left-padding 0es.
Applied to your case:
^(?!0)(?!\d{4}$)(?![4-9]\d{2}$)(?!3[7-9]\d$)(?!36[6-9]$)\d+$
Lets explain:
(?!0\d*) - does not start with 0
(?!\d{4}$) - does not have 4 digits, i.e. between 1000 and infinity
(?![4-9]\d{2}$) - it's not between 400 and 999
(?!3[7-9]\d$) - it's not between 370 and 399
(?!36[6-9]$) - it's not between 366 and 369
Test it.
^36[0-5]|(3[0-5]|[12]?[0-9])[0-9]$
^3(6[0-5]|[0-5]\d)|[12]\d\d|[1-9]\d|[1-9]$
Or if numbers like 05 can not be in input:
^3(6[0-5]|[0-5]\d)|[12]?\d?\d$
P.S.: Anyway no need of regex here. Use ToInt(), <=, >=
It really depends on your regex engine since they may not all be PCRE-style. I usually work to the lowest common denominator unless I know it will be targeting a minimum engine.
To that end, I'd just use something like:
^[1-9]|[1-9][0-9]|[1-2][0-9]{2}|3[0-5][0-9]|36[0-5]$
This will take care of (in order):
1-9.
10-99.
100-299.
300-359.
360-365.
However, unless you're absolutely required to use just a regex, I wouldn't. It's like trying to kill a fly with a thermo-nuclear warhead.
Just use the much simpler ^[0-9]{1,3}$ then use whatever language features you have to convert it to an integer and check it's between 1 and 365 inclusive:
def isValidDayOtherThanLeapYear (s):
if not s.matches ("^[0-9]{1,3}$"):
return false
n = s.toInteger()
if n < 1 or n > 365:
return false
return true
Your code will be more readable that way and I tend to rethink the use of regular expressions the second they start looking like they may be hard to read six months down the track.
This worked for me...
^[1-3][0-6]?[0-5]?$