Select the second instance of a character with regex [duplicate] - regex

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 3 years ago.
I want to select the second 'M' in the following string using regex.
So, the M after T.
P3Y6M4DT12H30M5S
Sometimes the string looks like one of these:
PT12H30M5S
PT12H30M5.234523S
I've tried multiple expressions and searched for a similar case but couldn't find anything.
Could someone help me build an expression to select the M after T so I can use it in my regex replace function?

(?!.+T.+)(M)
Selects everything until the first T and then selects everything until the first M and captures it.
Example: https://regex101.com/r/sPbQQj/2

Related

Grab a value from a string using Regex [duplicate]

This question already has answers here:
Regular expression to get a string between two strings in Javascript
(13 answers)
Closed 2 years ago.
I have a link that I want to grab a specific character out of. This is the link in question
"https://example.com/example-myexample/from/MyHouse/to/48DFjjhf333333333/view"
I want to grab the following id 48DFjjhf333333333 from this link using a regular expression. In this link /to/ and /view never change. The only thing that ever changes is the id that you see 48DFjjhf333333333.
I've tried the following regular expression:
\/to(.*?)\/view
This grabs everything along with /to/ and /view as follows /to/48DFjjhf333333333/view. I want to grab just the ID itself 48DFjjhf333333333
You just need to access the matching group with [1]
console.log("https://example.com/example-myexample/from/MyHouse/to/48DFjjhf333333333/view".match(/\/to\/(.*?)\/view/)[1])

Find two QnA maker link handler and assign each found regex an html <a> tag [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 3 years ago.
I want a regex for the following string:
For more: [Click here](https://www.google.ca) and [click me](https://www.google.com)
For that My current regex is as follows.
/\[.*\]\((((https?\:\/\/)|(www\.))(\S+))/ig
Give me the regex with that I can find two different links in the same line.
Right now I am finding 1 combined regex for both of them.
My guess is that we have URLs in (), which we can use an expression similar to, if that'd be the case:
\((https?[^\s]+)\)
with a capturing group, where our desired outputs are.
Demo 1
For capturing the [], we would just expand our expression:
(\[.+?])\((https?[^\s]+)\) //$ sign removed
Demo 2

How to end regex on first search [duplicate]

This question already has answers here:
My regex is matching too much. How do I make it stop? [duplicate]
(5 answers)
Closed 4 years ago.
I have the following string:
<center>DB Results:</center><center><b><br>ripster.ultima</b></center><center><b><br>raghav.jhavar</b></center></center></td></tr></table>
I want to extract "ripster.ultima" and "raghav.jhavar", so I used the following regex:
(?<=<center><b><br>)(.*)(?=<\/b><\/center>)
Now, this works in some cases, but not in all: https://regex101.com/r/imO8A8/4
In the link above, the first example is a single line. When I put in a single line, it does not select the individual strings. However, if its separated by a new line as seen in the second example, the strings I want are highlighted.
How do I get the strings in the first example?
You don’t need to group the first and the last patterns
<center><b><br>(.*?)<\/b><\/center>

Regular expression to select everything outside <> in a string [duplicate]

This question already has answers here:
Regular expression to extract text between square brackets
(15 answers)
Closed 4 years ago.
I'm not very handy with regex and I need to select everything outside <> to get the length of the string, excluding the "<>".
For example: first<second>third<fourth>fifth should give me first third fifth.
How can I do it? I spent some hours searching the web but I didn't really find what I needed. The regex is needed for use in javascript.
You can always replace the text between smaller than and greater than symbols using regex below.
/<\w+>/g
In this case the text which is outside remains.
See https://regexr.com/422jf

validation format - Reges expression [duplicate]

This question already has answers here:
How do I match an entire string with a regex?
(8 answers)
Closed 5 years ago.
I believe my validation is correct however it is not working.
My regular expression pattern is
ValidationExpression= "(I|II|III|IV)[DEF]?"
Basically, the user should put any of the first options then with optional D, E or F
Valid text Example: IIIC
Thank you
I don't know much about regex, but I did a quick bit of googling and came up with this:
https://regex101.com/r/KYpVbk/1
It explains how it works at the side :)