Forum Discussion

SuperTester's avatar
4 years ago

Extracting Image File Path from HTML Tag - Regular Expressions

Hello,   I am trying to come up with a regular expression that will match an image file path that is contained within a HTML tag.   <p><img src="file:///C:\Users\UserName\AppData\Local\Temp\ABC_I...
  • BenoitB's avatar
    4 years ago

    Yep, i've made a big mistake. As soon it's assigned it become a processed litteral and the \, as it is an escape char, doesn't exist anymore.

    No easy solution yet.


    You can try with the String.raw but the problem is the assignement of the value...




    function getImagePath(HtmlTag, Extension = ".png") {
      let posStart = 8 + aqString.Find(HtmlTag, 'file:///', 0, false);                      // +8 to exclude 'file:///'
      let posEnd   = Extension.length + aqString.Find(HtmlTag, Extension, posStart, false); // To include the extension
      return HtmlTag.substr(posStart, posEnd-posStart);
    function testIt() {
      const htmlTag = String.raw`<p><img src="file:///C:\Users\UserName\AppData\Local\Temp\ABC_Image_DE_tp07165ac8_2b0c_44e2_a4d8_1deabe5fb73e.png" width = ""height = ""></p>`;




    In regex or string manipulations the problem exist as long as the \ is an escap char.