Which RegEx expression to find in notepad++? [closed] - regex

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

Related

How do I get my regular expression to work with 3 numbers or more when two numbers are the same [closed]

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
The below regular expression works with 012, 201, 102, etc. I am trying to change the regular expression so that it matches 002, 200, 020O from a 4 digit number. I tried varies methods, but the regular expression is matching other patterns. Can someone give me some direction on how to resolve this issue. Thank you.
Working:
RegEx012 = re.compile(r'\b(?=[1-9]*0)(?=[02-9]*1)(?=[013-9]*2)\d+\b')
Not Working:
RegEx002 = re.compile(r'\b(?=[1-9]*0)(?=[1-9]*0)(?=[013-9]*2)\d+\b')
Results:
0250(good)
0260(good)
2052(bad)
2062(bad)
If you want to match a string with 2 times a zero and at least 3 digits, you could use a positive lookahead:
\b(?=[1-9]*0[1-9]*0[1-9]*\b)\d{3,}\b
Explanation
\b Word boundary
(?= Positive lookahead, assert what is on the right contains
[1-9]*0[1-9]*0[1-9]*\b Match 2 times a zero between optional digits 1-9
) Close lookahead
\d{3,} Match 3 or more digits
\b Word boundary
Regex demo
Or the other way around, assert 3 digits and match 2 times a zero between optional digits 1-9
\b(?=\d{3})[1-9]*0[1-9]*0[1-9]*\b
To match when the third character is a 3 (Or use a character class [03] to match either a 0 or 3)
\b(?=[1-9]*0[1-9]*0[1-9]*\b)\d{2}3\d*\b
Regex demo

Find numeric groups from alphanumeric string following pattern +[0..9] [closed]

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 3 years ago.
Improve this question
I have a string with alphanumerical characters like this:
hajshajs12 +1212121 12 1AAsdsd 5665789 +987 ++789 aBcD
Can I extract only the numeric characters with length >= 4 starting with + or without + using regex ?
So in the end I should have +1212121 5665789 +987 ++789
You can use this regex
([+](?:[+]\d{2,}|\d{3,})|\d{4,})\b
Regex Breakdown
( #Capturing group
[+] #Match + sign
(?: #Non-capturing group
[+]\d{2,} #Match another + followed by at least 2 digits
| #Alterantion (OR)
\d{3,} #Match at least 3 digits
)
| #Alterantion (OR)
\d{4,} #Match at least 4 digits
)
\b #Word boundary. Number shouldn't be in between alphabets

regex to validate strings with numbers and letters [closed]

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

Using captured groups in Regex [closed]

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

Regex for numbers and a dash [closed]

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