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)
Related
I need to put together a regex that matches a patter only if string does not begin with 'N'.
Here is my pattern so far [A-E]+[-+]?.
Now I want to make sure that it does not match something like:
N\A
NA
NB+
NB-
NCAB
This is for REGEXP_SUBSTR command in Oracle SQL DB
UPDATE
It looks like I should have been more specific, sorry
I want to extract from a string [A-E]+[-+]? but if the string also matches ^(N|n) then I want my regex to return nothing.
See examples below:
String Returns
N/A
F1/AAA AAA
NABC
FABC ABC
To match a character between A and E not preceded by N, you can use:
([^N]|^)[A-E]+
If you want to avoid fields that contains N[A-E] use a negation in your query using the pattern N[A-E] (in other words, use two predicates, this one to exclude NA and the first to find A)
To be more clear:
WHERE NOT REGEXP_LIKE(coln, 'N[A-E]') AND REGEXP_LIKE(coln, '[A-E]')
Ok I figured it out, I broadened the scope of the problem a little, I realized that I can also play with other parameters of REGEXP_SUBSTR in this case that I can have returned only second substring.
REGEXP_SUBSTR(field1, '^([^NA-D][^A-D]*)?([A-D]+[-+]?)',1,1,'i',2)
I still have to give you guys the credit, lot of good ideas that led me to here.
Just throw a [^N]? in front. That should do it.
OOPS...
That actually needs to include an " OR ^ "...
It should look like this:
([^N]|^)[A-E]+[-+]?
Sorry about that...It looks like the right answer already got posted anyway.
Given the below regex and text-
regex - #\{.*\}
text - "abc #{:abc :cde} dont-mtach #{:xyz :wqt} do-not do-not-not")
I would like to get only #{:abc :cde} #{:xyz :wqt} in the result. However the above also gives me dont-match in the result. Any ideas how I should modify the regex ?
#\{.*?\}
Make your * non greedy.Or simply use
#\{[^}]*\}
See demo
I would like to get super scripted text via following html string.
testing to <sup>supers</sup>cript o<sup>n</sup>e
The result I would like to get is like below
supers
n
This is what I tried right now
But the result is not what I want.
<sup>supers
<sup>n
Could anyone give me suggestion please?
You can use lookbehind in your regex:
(?<=<sup>)[^<]*
Update Demo
Use this if there may be other HTML tags between <sup> and </sup>:
(?<=<sup>)(.*?)(?=<\/sup>)
Check the demo.
You were close, just not capturing your match:
Updated regex
(?:<sup>)([^<]*) I just added a capture group around your match
(?<=<sup>)([^<]*?)(?=<\/)
This should work.
See demo.
http://regex101.com/r/sA7pZ0/13
if I have a website like: www.google.com/en/my-page/anotherpage
how is it possible that with reg-ex to get: /en/my-page ? I am using this reg-ex in the IIS?
So far I have done something similar to this:
^(?:\\.|[^/\\])*/((?:\\.|[^/\\])*)/
but it is returning /en/my-page/ and I want it to return /en/my-page
In grep your regex is returning the string "www.google.com/en/". You can simply use the following regex if positive look behind is not mandatory :
(/[^/]+)+
You could use a look-ahead assertion to get rid of the last slash:
/\/.*(?=\/)/
This one should suit your needs:
^[^/]+(/.*)/[^/]+$
Visualization by Debuggex.
The output your looking for is in the first captured group.
Demo on RegExr.
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.