Regular expression - empty or a minimum of 6 characters [duplicate] - asp.net

This question already has answers here:
What is the expression on RegularExpressionValidator to check if the Textbox text is 6 or more characters long?
(2 answers)
Closed 8 years ago.
I want to use an ASP:RegularExpressionValidator to enforce a minimum character count (6) but only if the field is NOT empty.
Could anyone help me with the regex for this?

Try this regular expression:
^(?:.{6,}|)$

Related

Replace last characters of a string with its entire elements [duplicate]

This question already has answers here:
Extracting the last n characters from a string in R
(15 answers)
Closed 3 years ago.
I have an element in my dataframe which I want to modify.
I have a column with the following type of values
https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345
I want to replace the entire string with just the last 5 characters (i.e)
Replace the entire character string with 12345 in this case.
How do I achieve this?
Thanks a lot.
One option is using a positive look behind using stringr::str_extract
str_extrct('https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345',
'(?<=proposalId\\=)\\d+')
#Simple option
str_extract('https://mns-xyz-eu.abc.com/ccs/proposal?action=view&proposalId=12345', '\\d+')

Remove Characters in R [duplicate]

This question already has answers here:
Replace all particular values in a data frame
(8 answers)
How do I deal with special characters like \^$.?*|+()[{ in my regex?
(2 answers)
Closed 4 years ago.
I have a large data frame with a character value in various columns and rows. The character is [subnet].
I am trying to get rid of it by writing the following code
new_data[]=lapply(new_data, gsub, pattern="[subnet]", replacement='')
However, it seems like although "subnet" is disappearing, I am ending up with
"[]" for every instance of the character.
Any idea or fix would be appreciated.

Trying to validate two different format in one regular expression [duplicate]

This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 5 years ago.
I want to validate these formats in one regular expression in asp.net:
XX-XXXXXXX or XXX-XX-XXXX
These have to be numeric only no characters except the "-".
Is this possible? I've been trying without any success so I want to ask the experts.
Thanks,
Pune
The following should work given your requirements.
"(^\d{2}-\d{7}$)|(^\d{3}-\d{2}-\d{4}$)"
Try something like this:
/^([0-9]{2}-[0-9]{7}|[0-9]{2}-[0-9]{2}-[0-9]{4})$/
[0-9] means any character from 0 to 9.
{X} means X times
| means "or"
- means "-"
and ( and ) delimits a group for replacing
^ and $ delimit the beginning and the ending of the match.

R - Weird behavior of grepl [duplicate]

This question already has an answer here:
grepl not searching correctly in R
(1 answer)
Closed 6 years ago.
I want to know if there is a certain string contained in another string. This works fine here:
grepl("a","a")
However, what I actually want to test is the following and this one doesn't work:
grepl("is.na(x)","is.na(x)")
Can anyone help?
You can escape the special characters like this:
grepl("is\\.na\\(x\\)","is.na(x)")
[1] TRUE

R displays numbers in scientific notation [duplicate]

This question already has answers here:
How can I paste 100000 without it being shortened to 1e+05? [duplicate]
(3 answers)
Closed 9 years ago.
The result of function was displayed in scientific notation, I want to change it back to normal, but only for that function, I don't want to change the global setting. Can anyone help?
You can do:
format(functionResult, scientific=FALSE);
or:
as.integer(functionResult);

Resources