Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I want to match a string where there are 5 characters where first four characters are A-Z and 5th is a digit. Also the first and the fourth character should be same.
I have a regex: [A-Z]{4}\d
However this wont check if 1st and 4th character are same. Please help
Regex: ^([A-Z])[A-Z]{2}\1\d$
1. ^ start of string.
2. ([A-Z]) capture first character.
3. [A-Z]{2} match next two character which can be in A-Z
4. \1 using captured group which contains first character of string.
5. \d a digit which can be 0-9
6. $ for end of string.
Regex demo
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm working on a regex to take #users
In italian, sometime there is something like l'#Orazio.
I can't find the right way to take this.
I'm using this line /(?<=^|\s)(#(\S+))/
this is my online tester
https://regex101.com/r/s5BTm0/12
as you can see I have an issue with the case 4
Any tips?
You may use
(?<!\S)(?:\w+['’])?#(\S+)
(?<!\w)(?:\w+['’])?#(\S+)
See the regex demo
Details
(?<!\S) - whitespace or start of string must appear immediately to the left of the current location
(?<!\w) - a location the is not immediately preceded with a word char
(?:\w+['’])? - an optinal sequence of 1+ word chars and then ' or ’
# - a # char
(\S+) - Capturing group 1: one or more non-whitespace chars.
Use an optional group:
(?<=^|\s)(?:\w?'?)(#(\S+))
https://regex101.com/r/s5BTm0/5
For more than 1 letter in front, use:
(?<=^|\s)(?:(\w*')?)(#(\S+))
https://regex101.com/r/s5BTm0/8
And to match all your updated cases:
https://regex101.com/r/s5BTm0/10
For different types of apostrophes:
(?<=^|\s)(?:(\w*['´])?)(#(\S+))
https://regex101.com/r/s5BTm0/13
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need help to create a regex to validate one string, the string must be 12 characters, they can all be numbers or they can be 11 numbers and a letter, the letter can be anywhere between those numbers.
Some examples:
20710117540C
00A109822346
005109822346
K05109822346
// error cases
KY0510982234
KY05109822345
5505109822345
Thanks!
You can use this regex that will meet your requirements,
^(?:\d{12}|(?=\d*[a-zA-Z]\d*$)[\da-zA-Z]{12})$
Explanation:
^ - Start of string
(?: - Start of non-grouping pattern
\d{12} - Matches exactly 12 digits
| - alternation for another case where 11 characters can be any digits and one letter
(?=\d*[a-zA-Z]\d*$) - Look ahead to ensure the the incoming data consists of some digits and exactly one occurrence of alphabet
[\da-zA-Z]{12} - Consume 12 characters consisting of numbers and alphabet
)$ - End of non capturing group and end of input
Demo1
Another simple regex you can use is this,
^(?=\d*[a-zA-Z]?\d*$)[\da-zA-Z]{12}$
Explanation:
^ - Start of string
(?=\d*[a-zA-Z]?\d*$) - Look ahead ensuring the input contains some digits and either one alphabet or no alphabets.
[\da-zA-Z]{12} - Match and consume exactly 12 characters
$ - End of input.
Demo2
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Im looking for a regular expression for a textbox thats accepts either 10 digits, or 8 digits, followed by a dash, followed by 2 digits. Examples:
1212345678
or
12345678-91
If you just want to check if the input is valid without matching any content, this one should be enough:
^\d{8}-?\d\d$
Beginning with 8 digits, followed (or not) by an optional dash, and another 2 digits up to the end.
This Should Work.
((?:^[0-9]{10})|(?:^[0-9]{8}(?:\-\d{2})*))$
Input:
1212345678
12345678-91
12345678901112-10
1234567890-12
Output:
1212345678
12345678-91
See: https://regex101.com/r/AzbVXt/2
^\d{8}(\d{2})?(-\d{2})?$
^ and $ : match from the begging to the end
\d{8} : 8 digits
(\d{2})? : optional two other digits
(-\d{2})? : optional dash, with two other digits
This will match
1212345678
121234567800
Not 1212345678001
1212345678-
1212345678-00
Not 1212345678-001
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have in Notepad++ plenty of datetime texts like:
'20160310 17:59:00'
And I want to add '-' character to separate numbers in the date like
'2016-03-10 17:59:00'
How I would be a RegEx expression to do that?
The following regex expression:
('\d{4})(\d{2})(\d{2} \d{2}:\d{2}:\d{2}')
Combined with the following replace expression:
$1-$2-$3
will achieve what you want.
Explanation:
('\d{4}) capture group 1: an apostrophe followed by 4 digits
(\d{2}) capture group 2: 2 digits
(\d{2} \d{2}:\d{2}:\d{2}') capture group 3: 2 digits, a space, 2 digits, a colon, 2 digits, a colon and 2 digits, followed by an apostrophe
$1-$2-$3 - capture group 1, followed by a -, followed by capture group 2, followed by a -, followed by capture group 3
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to looking for regex which allows any comma separated values. Like this.
23,23,23
233-2-3,23,23
23/23/2333,22-22-2222,23
I have tried couple of things but nothing fits 100%.
[^,;]+
/(?!,)(?:(?:,|^)([-+]?(?:\d*\.)?\d+))*$/
(\d+, ?)+(\d+)?
My use case is , if my string pass through above regex, I will parse all the values and store it into an array. If string doesn't have any single , than leave that string.
thanks
As stated in the comments, we have come to the following solution:
(?m)^(?:\d+[\/,-]){2,}\d+$
Explanation:
(?m) : make ^ and $ match start and end of line respectively.
^ : Start of line
(?: : Ignore group
\d+ : Match a digit 1 or more times
[\/,-] : Followed by a / or , or -
) : Closing parenthesis for the ignore group
{2,} : Match two times or more
\d+ : Match a digit 1 or more times
$ : End of line
Online demo