Jump to content
Sign in to follow this  
leuce

Regex help, please

Recommended Posts

leuce

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

 

Share this post


Link to post
Share on other sites
iamtheky

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)

 

 


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

Share this post


Link to post
Share on other sites
leuce

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

Share this post


Link to post
Share on other sites
jguinch

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)

 

Share this post


Link to post
Share on other sites
leuce

Thanks, jguinch, you're right -- the simpler regex makes sense :-)

Share this post


Link to post
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
Sign in to follow this  

×