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])
Related
This question already has answers here:
Regex catch string between two strings, multiple lines
(4 answers)
Closed 2 years ago.
I'm trying to get the text from the [QOUTE] and [/QUOTE] but can seem to get it correctly. I'm just trying to pick it out and delete it. So I want to extract the text within as well as the actual HTML [QUOTE] parts. Just want to get rid of that entire code block via regex:
What I'm working with:
\[QUOTE(.+)|\[\/QUOTE]|
Text Example:
[QUOTE="", post: 1910681, member: 001""]
This is where the quote is located
[/QUOTE]
[URL unfurl=""true""]https://www.google.com[/URL]
Assuming those tags can't be nested, you can use the following regex with the single-line flag to match the tags and their content :
\[QUOTE\b.*?\[/QUOTE]
You can try it here.
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
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
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>
This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
Closed 6 years ago.
I came up with the following
([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})
I would also like to remove emails that start with a number or -. By remove I mean to select only the address and not to remove the entire match.
Is there a way to do that?
^(?:\d+|-+)?([\w.%+-]+#[A-Za-z0-9.-]+\.[A-Za-z]{2,4})$
This should do the trick. It'll capture emails but also filter out ones that start with a number or the - character and pulls the email from it.