I have this regex:
[0-9]+,[0-9]{2}
https://regexr.com/3joum
And i can enter
10,00
1,00,
100,00,
1000,00
But i also want to have this:
1.000,00
10.000,00
100.000,00
1000.000.00
and so on... to that be valid also. Any suggestions?
It's kind of hard to tell what rules exactly you're looking to follow with your regex. How about this?
([0-9]+[,.])+[0-9]{2}(,)?
This regex will allow you to match currency that uses either a , or a . and can even end in a , like in some of your examples.
Related
I have text in a column like /AB/25MAR92/ and /AB/25MAR1992/. I am trying to extract just 25MAR92 and 25MAR1992 from the column for a date calculation that I have to work on. Can you please help with the REGEXP_SUBSTR function for this issue?
Thanks!
You could try:
\b\d{1,2}[A-Z]{3}\d{2,4}\b
but this will also match 02MAR992. To exclude this possibility use:
\b\d{1,2}[A-Z]{3}(?:\d{2}|\d{4})\b
This will match 02MAR1992 and02MAR92 but will not match02MAR992.
I suggest using a pattern like this:
\/(\d{2}[A-Z]{3}(19|20)?\d{2})\/
Years are limited to 1900-2099.
Demo
If you do not want to allow any 2-digit value for the day \d{2},
you could add this pattern instead (0[1-9]|[12][0-9]|3[01]) that matches 01-31;
\/((0[1-9]|[12][0-9]|3[01])[A-Z]{3}(19|20)?\d{2})\/
Or if you allow dates like /AB/2MAR92/ that have days without a leading zero
add (0[1-9]|[12][0-9]|3[01]|[1-9]) instead:
\/((0[1-9]|[12][0-9]|3[01]|[1-9])[A-Z]{3}(19|20)?\d{2})\/
I've used / as anchors. If you don't like that, you can use \b.
In reaction to your latest comments, my recommended pattern looks like this:
\b\d{1,2}[A-Z]{3}(?:19|20)?\d{2}\b
I want to allow input values as A+,B+,A-,B- or 2 decimal values like 100.00, 90.0 like this
how to write regex for above input? simply I want to allow grades(A+,A-,B+,B-),decimal values (10.05,20.00).
The below regex will helpful to you:
[AB][+-]|\d{2}\.\d{2}
Description and Demo At: Demo
For what I am seeing, I would use this regex (I bet you can optimize it).
^([A-GOa-go][+-])|((\d{1,2}(?!\d)\.\d{2}|100\.00),(\d{1,2}(?!\d)\.\d{2}|100\.00))$
Here is the demo
Try this:
([AB][+-]|(100|\d{2})\.\d{2})
This, in my opinion, will work for what you are expecting
Online test : RegExr.com
EDIT :
Following what you are expecting for, i suggest you this regex :
^([AB][+-]|(100|\d{2})\.\d{2})$
Will match only if the entire string matches, and no longer return a 02.00 match for 102.00 (for example)
Short story:
Is there a way to prevent Notepad++ from interpreting all parts of a string as regex?
The long story:
I have a list of German cities. In Germany some cities have the suffix a.d. (meaning close by) plus the name of a river to differentiate this city from others with the same name.
Unfortunately the suffix is written in various forms, for example:
Dillingen a. d. Donau
Dörnfeld a. d.Ilm
Eldena a.d.Elde
Limburg a d Lahn
To be able to join this list with other data I need a coherent form, for example:
Dillingen a.d. Donau
Dörnfeld a.d. Ilm
Eldena a.d. Elde
Limburg a.d. Lahn
I tried to search for
(a.d.)\b.+\b
but, of course, Notepad++ interprets a.d. as regex (. = any letter) giving also results such as
Fürstenwalde/Spree
Immenstaad am Bodensee
Jänschwalde Ost
making it impossible to search and replace all.
How can I realize this using regex?
I guess the answer is fairly easy but I found no hint in the forum or Notepad++ documentation.
Can someone help? Thanks a lot in advance!
Best,
David
\ba\s*\.?\s*d\b.+
You can use this.a.d here . will match any character so escape it.See demo.
https://regex101.com/r/eX9gK2/7
I am trying to find the correct regex (for use with Java and JavaScript) to validate an array of day-of-week and 24-hour time formats. I figured out the time format but am struggling to come up with the full solution.
The regex needs to validate patterns which include one or more of the following, separated by a comma.
{two-character day} HH:MM-HH:MM
Three examples of valid strings would be:
M 5:30-7:00
M 5:30-7:00, T 5:30-7:00, W 18:00-19:30
F 12:00-14:30, Sa 6:45-8:15, Su 6:45-8:15
This should validate a 24-hour time:
/^((M|T|W|Th|Fr|Sa|Su) ([01]?[0-9]|2[0-3]):[0-5][0-9]-([01]?[0-9]|2[0-3]):[0-5][0-9](, )?)+$/
Credit for the time bit goes to mkyong: http://www.mkyong.com/regular-expressions/how-to-validate-time-in-24-hours-format-with-regular-expression/
you can try this
[A-Za-z]{1,2}[ ]\d+:\d+-\d+:\d+
You could try this: ([MTWFS][ouehra]?) ([0-9]|[1-2][0-9]):([0-6][0-9])-([0-9]|[1-2][0-9]):([0-6][0-9])
I'd go with this:
(((M|T(u|h)|W|F|S(a|u)) ((1*\d)|(2[0-3])):[1-5]\d-((1*\d)|(2[0-3])):[1-5]\d(, )?)+
This should do the trick:
^(M|Tu|W|Th|F|Sa|Su) \d{1,2}:\d{2}-\d{1,2}:\d{2}(, (M|Tu|W|Th|F|Sa|Su) \d{1,2}:\d{2}-\d{1,2}:\d{2})*$
Note that you show T in your example above which is ambiguous. You might want to enforce Tu and Th as shown in my regex.
This will capture all sets in an array. The T in the short day of week list is debatable (tuesday or thursday?).
^((?:[MTWFS]|Tu|Th|Sa|Su)\s(?:[0-9]{1,2}:[0-9]{2})-(?:[0-9]{1,2}:[0-9]{2})(?:,\s)?)+$
The (?:) are non-capturing groups, so your actual matches will be (for example):
M 5:30-7:00
T 5:30-7:00
W 18:00-19:30
But the entire line will validate.
Added ^ and $ for line boundaries and an explicit time-time match because some regular expression parsers may not work with the previous way that I had it.
I have a set of strings that I'd like to parse in MATLAB 2012 that all have the following format:
string-int-int-int-int-string
I'd like to pluck out the third integer (the rest are 'don't cares'), but I haven't used MATLAB in ages and need to refresh on regular expressions. I tried using the regular expression '(.*)-(.*)-(.*)-\d-(.*)' but no dice. I did check out the MATLAB regexp page, but wasn't able to figure out how to apply that information to this case.
Anyone know how I might get the desired result? If so, could you explain what the expression you're using is doing to get that result so that others might be able to apply the answer to their unique situation?
Thanks in advance!
str = 'XyzStr-1-2-1000-56789-ILoveStackExchange.txt';
[tok] = regexp(str, '^.+?-.+?-.+?-(\d+?)-.+?-.+?', 'tokens');
tok{:}
ans =
'1000'
Update
Explanation, upon request.
^ - "Anchor", or match beginning of string.
.+? - Wildcard match, one or more, non-greedy.
- - Literal dash/hyphen.
(\d+?) - Digits match, one or more, non-greedy, captured into a token.
^.*?-.*?-.*?-(\d+)-.*?-.*?$
OR
^(?:[^-]*?-){3}(\d+)(?:.*?)$
Group1 now contains your required data