I want to grab an img
tag from text returned from JSON data like that. I want to grab this from a string:
<img class="img" src="https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-frc3/1239478_598075296936250_1910331324_s.jpg" alt="" />
What is the regular expression I must use to match it?
I used the following, but it is not working.
"<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>"
HTML Images Syntax The <img> tag is empty, it contains attributes only, and does not have a closing tag. The <img> tag has two required attributes: src - Specifies the path to the image. alt - Specifies an alternate text for the image.
As i understood, ngIf removes element from the DOM, and hence when ngIf evaluates to falsy value, it removes the img element from the DOM, now when I toggle back to true value, it's bringing back the cached url instead of rendering fresh img element.
\d for single or multiple digit numbers It will match any single digit number from 0 to 9. \d means [0-9] or match any number from 0 to 9. Instead of writing 0123456789 the shorthand version is [0-9] where [] is used for character range. [1-9][0-9] will match double digit number from 10 to 99.
To match a character having special meaning in regex, you need to use a escape sequence prefix with a backslash ( \ ). E.g., \. matches "." ; regex \+ matches "+" ; and regex \( matches "(" . You also need to use regex \\ to match "\" (back-slash).
You could simply use this expression to match an img tag as in the example :
<img([\w\W]+?)/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With