Jump to content

Regex help, please


Recommended Posts

Hello everyone

I need to change this:

<img class="img-inline" data-inlineattributes="@xtm-id='22019'" data-inlineid="77" data-inlinetype="G" data-inlinename="t" onmouseout="hideTooltip();" src="https://asdf/getInlineImage.serv?type=G&amp;id=1&amp;size=11">

into this:

{{{77}}}

and so I use this in my script:

$one = StringRegExpReplace ($one, '(<img class="img-inline" data-inlineattributes="@xtm-id=''\d+''" data-inlineid=")(\d+)(".+?">)', "{{{$2}}}")

...but it doesn't match it.  Where is the error?

Thanks!
Samuel

 

Link to comment
Share on other sites

quote issues with your double singles, here you can see, though there is probably a better fix

$string = '<img class="img-inline" data-inlineattributes="@xtm-id=' & '22019' & '" data-inlineid="77" data-inlinetype="G" data-inlinename="t" onmouseout="hideTooltip();" src="https://asdf/getInlineImage.serv?type=G&amp;id=1&amp;size=11">'

$one = StringRegExpReplace ($string, '(<img class="img-inline" data-inlineattributes="@xtm-id=' & '\d+' & '" data-inlineid=")(\d+)(".+?">)', "{{{$2}}}")

msgbox(0, '' , $one)

 

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

Thanks, but I'm afraid there's something wrong with the  syntax of $string in your example.  As far as I know, it should be:

$string = '<img class="img-inline" data-inlineattributes="@xtm-id=' & "'" & '22019' & "'" & '" data-inlineid="77" data-inlinetype="G" data-inlinename="t" onmouseout="hideTooltip();" src="https://asdf/getInlineImage.serv?type=G&amp;id=1&amp;size=11">'

in which case your regular expression does not work.  Remember, the original string is ["@xtm-id='22019'"], not ["@xtm-id=22019"].

Samuel

==

Added: I solved it with a simple hack, namely by removing all single quotes before doing the regex.

Edited by leuce
Link to comment
Share on other sites

Maybe too late, but one way :

$string = '<img class="img-inline" data-inlineattributes="@xtm-id=''22019''" data-inlineid="77" data-inlinetype="G" data-inlinename="t" onmouseout="hideTooltip();" src="https://asdf/getInlineImage.serv?type=G&amp;id=1&amp;size=11">'
$one = StringRegExpReplace($string, ".+data-inlineid=([""'])(\d+)\1.+", "{{$2}}")
ConsoleWrite($one)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...