0

For example,

Say I want to change all occurances of <img src="https://www.blahblah.com/i" title="Bob" />

To simply

Bob

This is for vb.net

Basically there are plenty of such pattern in a big string. I want to change every one of them.

This is what I tried

Dim tdparking = New System.Text.RegularExpressions.Regex("\w*       (<img.*title="")(.*)"" />")

After that I suppose I would need to do some substitution. But how?

How would I do so?

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
user4951
  • 32,206
  • 53
  • 172
  • 282

3 Answers3

0

  var str = '<img src="https://www.blahblah.com/i" title="Bob" />';
      str = str.replace(/<img[^>]*title="(\w+)"[^>]*>/,"$1");
  document.write(str);
      
        
Kerwin
  • 1,212
  • 1
  • 7
  • 14
  • str.replace can recoqnize regular expression? – user4951 Nov 09 '15 at 02:26
  • @JimThio No, it's Javascript. You should probably tag your question as VB.NET since that what it looks like you're using. If you remove the leading and trailing `/`, then the pattern should work in .NET as well. – Kenneth K. Nov 09 '15 at 02:40
  • As Kenneth said it's javascript, and it's the regex:`]*title="(\w+)"[^>]*>` , see [Demo](https://regex101.com/r/kY6rS2/1),and it should also worked in .net – Kerwin Nov 09 '15 at 08:38
0

You can use this regex: \<img[^\<\>]+title=\"([a-zA-Z]+)\"[^\<\>]+\/\> and return $1 of the matching pattern:

In PHP it should be:

preg_match_all('#\<img[^\<\>]+title=\"([a-zA-Z]+)\"[^\<\>]+\/\>#', $html, $matches);
var_dump($matches[1]);

Regards,

Dat Pham
  • 1,765
  • 15
  • 13
0

Everyone is making this waay to hard - Here it is in vb.net

   Dim reg as Regex = New Regex("(?<=title="""").+(?="""")")
   Dim str as String = "<img src=""https://www.blahblah.com/i"" title=""Bob"" />"
   Dim match as String = reg.match(str).value

Depending on how the string is inputted you will either need

"(?<=title="""").+(?="""")" 'If there is Double quotes ("")

or

"(?<=title="").+(?="")" 'Or single quotes (")

Also there is no need for you to get downvoted - here is a point back

Nefariis
  • 3,451
  • 10
  • 34
  • 52