I need to validate following string using Regular Expressions.
These are the constraints which apply for this string.
From beggining it has 9 numbers.
In the end it has character 'V' or 'X'. They can be simple or capital.
Whole length of string must be 10.
Ex: 84256142V, 547812375X
Can anyone provide me RegEx for validate this.
^\d{9}[VX]$ if you put the regex engine in case-insensitive mode, ^\d{9}[vVxX]$ otherwise.
Depends on the language, but it will be something like this:
^[0-9]{9}[VvXx]$
This is the Regex you need: /^(\d){9}(V|X)$/i
Related
I'm trying to use angular's ng-pattern attribute to enforce that the text in an input box matches a particular regular expression. I'm doing this for form validation. The input I'm using this on is a phone field. The phone field can accept 10 digit phone numbers but I don't want to require a specific format from my users other than it must contain a 10 digit number in there somewhere. So these would both be valid.
555-555-5555
(555) 555-5555
On the backend, I would just remove all formatting and store the raw digits. In the past for this what I've done is to remove all non-numeric characters and then just made sure the length == 10. It's simple enough to do in a couple of lines of code, but is it something regular expressions can handle? This isn't something I've ever tried to make a regular expression do. I don't want to support specific formats because I don't care if they accidentally enter an extra space or if they want to type their phone number like this: 55-55-55-55-55. It really doesn't matter to me, I just want the regex to match if there are 10 digits and no more somewhere in the string.
Thanks for the help guys!
To allow just 10 digits in a string with a regex, no more no less, you can use
^(?:\D*\d){10}\D*$
See demo (\D replaced with [^\d\n] to exclude newline for demo only).
The (\d\D*?){10} regex will find the match in a string with more than 10 digits.
^(?!(?:.*?\d){11,})[^a-zA-Z\n]+$
Try this.See demo.
https://regex101.com/r/iQ4nW0/1
You can make attribute type directive for it and set validity with dynamic regular expression.
I have an input json:
{"id":12345,"mgrs":"04QFJ1234567890","code":"12345","user":"db3e1a-3c88-4141-bed3-206a"}
I would like to extract with regular expression MGRS of 1000 kilometer, in my example result should be: 04QFJ1267
First 2 symbols always digits, next 3 always chars and the rest always digits. MGRS have a fix length of 15 chars at all.
Is it possible?
Thanks.
All you really need to do is remove characters 8-10 and 13-15. If you want/need to do that using regex, then you could use the replace method with regex: (EDIT Edited to remove the rest of the string).
.*?(\w{7})\d{3}(\d{2})\d+.*
and replacement string:
$1$2
I see now you are using Java. So the relevant code line might look like:
resultString = subjectString.replaceAll(".*?(\\w{7})\\d{3}(\\d{2})\\d+.*", "$1$2");
The above assumes all your strings look like what you showed, and there is no need to test to be sure that "mgrs" is in the string.
I need to create a regex query for a Google Analytics goal. The goal url must contain:
thankYou.sjs?donate_page
However, there are many urls than can render this string, all with other modifiers that I don't care about.
Please advise.
#ExplosionPills: I think you forgot about the special meaning of the question mark.
If you don't escape it, your expression:
^thankYou.sjs?donate_path$
Would match
thankYou.sjsdonate_path
or
thankYou.sjdonate_path
Not to mention the special meaning of dot.
So I guess something like this should work:
thankYou\.sjs\?donate_path
Furthermore if it's possible that the donate_path is not the first in the query string you can use this:
thankYou\.sjs\?([^&]*&)*donate_path
Just the string itself will work. If you want only this string, just use the start/end of string zero-width assertions:
^thankYou\.sjs\?donate_path$
I want a regular expression for format xx-xxxx can somebody help? It will take numbers and
characters. I have no idea about regular expressions. also can some explain that how whole expression works?
Thanks
Assuming that the string will be only containing exactly that string with no leading or trailing whitespace:
/^[a-zA-Z0-9]{2}-[a-zA-Z0-9]{4}$/
If you need to find that pattern within another string (a paragraph?) you would use:
/\b[a-zA-Z0-9]{2}-[a-zA-Z0-9]{4}\b/
The expression:
\A[0-9a-zA-Z]{2}-[0-9a-zA-Z]{4}\Z
will also work.
I am using the following regular expression to validate e-mails, but it allows empty strings as well, how can I change it to prevent it:
^[\w\.\-]+#[a-zA-Z0-9\-]+(\.[a-zA-Z0-9\-]{1,})*(\.[a-zA-Z]{2,3}){1,2}$
I am using an asp:RegularExpressionValidator. My other option is to add on a asp:RequiredFieldValidator, but I am curious if this is possible to check for blanks in my RegularExpressionValidator, so I don't have to have 2
see http://www.regular-expressions.info/email.html
That expression does not match empty strings. The expression starts with ^[\w\.\-]+ this translates to "The string must start with a word character, period or slash. There can be more than one of these." There must be something else wrong or you copied the expression incorrectly.
This RegEx validates if a given string is in a valid email-format or not:
/^[a-zA-Z0-9\_\-\.]+\#([a-zA-Z0-9\-]+\.)+[a-zA-Z0-9]{2,4}$/