Find multiple instances of substring in a string using Regular Expressions? - c++

I have many lines such as this:
string s = "Some HTML with two <A HREF="links"> in one <A HREF="line">";
I need to use regular expressions to get the URLs in between the quotation marks, like this:
string all_links[] = {"links", "line"};
How would I go about doing this? Thank you.

As per your given string sample.
Use [^\HREF="]+(?=">)
Demo

Related

Regex Expressions for value extraction from URL param string

I have a string where I'd like to extract some values with regex.
Whole string:
event=B:Rel&time=1511879856&date=20171128-143736&ref=57b3e1ab741d5a017ab8009033350b18&dir=out&src_if=GW1&dst_if=PRI1
I would like to isolate the values between the = and the next & creating this result set for the string given above.
B:Rel
1511879856
20171128-143736
57b3e1ab741d5a017ab8009033350b18
out
GW1
PRI1
Thanks for the help!
Try this:
[^=]+=([^&]+)(?:&|$)
DEMO: https://regex101.com/r/Z3pcR4/1
Depending on your language, you could split the input on this regex:
&?[^=]*=

Regex Python, Find Everything Inbetween Quotes after Keyword

I have strings that looks like this:
"Grand Theft Auto V (5)" border="0" src="/product_images/Gaming/Playstation4 Software/5026555416986_s.jpg" title="Grand... (the string continues for a while here)
I want to use regex to grab this: /product_images/Gaming/Playstation4 Software/5026555416986_s.jpg
Basically, everything in src="..."
At the moment I produce a list using re.findall(r'"([^"]*)"', line) and grab the appropriate one, but there's a lot of quotes in the full string and I'd like to be more efficient.
Can anyone help me put together an expression for this please?
Try with this
(?<=src=").+(?=" )
Use this as RE :
src="(.+?)"
This will return result as you want.
re.findall('src="(.+?)"', text_to_search_from)

Parse string with regular expression using JavaScript

Need help with regular expression in JavaScript
I have a semicolon delimited string of hyperlinks:
"<a onclick="RemoveValue('Asthma', '1')">Asthma</a>; <a onclick="RemoveValue('Alzheimer’s Disease', '2')"> Alzheimer’s Disease</a>; <a onclick="RemoveValue('Depression', '3')">Depression</a>"
I need to remove below part of the string using regular expression:
“<a onclick="RemoveValue('Alzheimer’s Disease', '2')"> Alzheimer’s Disease</a>”
Any help would be appreciated.
Thanks,
Since I have no clue to why or what you're trying to accomplish the regex may not work. Next time, please give us some context. It helps us and you. The other thing is try to show what you've tried yourself so we don't just repeat the same suggestion you've already tried.
Anyway here's a simple regex that will do this, but technically you could just do a replace to remove the occurrences of the string you provided.
<a[^>]+onclick="RemoveValue\('Alzheimer’s Disease'[^"]+">[^<]+</a>(?:;\s)?
Regex Demo
For the JS side it should look something similar to this:
var str = "<a onclick=\"RemoveValue('Asthma', '1')\">Asthma</a>; <a onclick=\"RemoveValue('Alzheimer’s Disease', '2')\"> Alzheimer’s Disease</a>; <a onclick=\"RemoveValue('Depression', '3')\">Depression</a>";
var re = /<a[^>]+onclick="RemoveValue\('Alzheimer’s Disease'[^"]+">[^<]+<\/a>(?:;\s)?/gi;
var reOutput = str.replace(re, "");
console.log(reOutput);
Fiddle Demo - Check console window.

How to use regular expression edit the content?

I'm edit an rst file for a document. There are lot of image links I have to edit them one by one, I'd like to ask, is there anybody can help write a regular expression that can transfer it in one time.
The original text looks like:
*Figure 1.2: Where is the dog?* <dog.html#fig_dog>
I'd like it translate it to:
:ref:fig_dog
And there is another one:
*How are you* <how_are_you.html>
I'd like it translate it to:
:ref:how_are_you
I have try some expression in editplus or notepad++, but i can't match them very well.
Search:
\*.*?\*\s*<(?:.*#)?([^.>]+)(\.[^>]*)?>
Replace:
:ref:\1
split into two regexes
To match before the html
<(.*).html.*?>
To match the anchor
<.*.html#(.*?)>

Extract some strings

need some help with this RegEx magic..
I have this:
delete
and this:
(<a)*([^>]*>)[^<]*(</a>)
$1 = <a
$2 = href="/en/node/1032/delete?destination=node%2F5%2Fblog">
$3 = </a>
I need some aditional strings:
1032
href="/en/ en is dynamic!
How can I get this strings?
Used in php
Your sample could be captured with
(<a)\b.*?((href="/en/).*?(?</)(\d+)/.*?").*?>).*?(</a>)
...but perhaps replacing the "en" with something broader, depending on what you want to capture.
HOWEVER, and I want to emphasize this, don't use regex to parse HTML. The above regex won't work for certain HTML-valid input, and due to the limitations of regex it cannot be refined to work for every possible case. You'll get better, more correct results with an HTML or XML parser.
([^/ ]). That will give you
href="
en
node
1032