Sign in to follow this  
Followers 0
Champak

StringRegExpReplace help with html tags

14 posts in this topic

#1 ·  Posted (edited)

Could someone who me how to remove '<' and '>' and everything between them please? Basically replace it with nothing.

Edited by Champak

Share this post


Link to post
Share on other sites



local $s = "Some Stuff <and> Some Other Stuff"

msgbox(0, '' , $s)

$sOut = StringRegExpReplace($s , "<.*>" , "")

msgbox(0, '' , $sOut)


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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Might want to watch for nested:

Global $gsString = "i am <something<here><something> else>a string"
ConsoleWrite(StringRegExpReplace($gsString, "<.*[^<]>", "") & @CRLF)
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

?  What are you accounting for that I am missing

Global $s = "i am <something<here><something> else>a string"

$sOut1 = StringRegExpReplace($s , "<.*>" , "")

$sOut2 = StringRegExpReplace($s, "<.*[^<]>", "")

msgbox(0, '' , $sOut1)
msgbox(0, '' , $sOut2)
Edited by boththose

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

Share this post


Link to post
Share on other sites

I changed it to that... I had a lazy quantifier in it before and realized it didn't remove the last forward arrow, so I just removed the lazy without checking if it made a diff...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

Ah, when it comes to regex I'm constantly afraid I am overlooking something I should have learned a long time ago.


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

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks I tried it but it doesn't work for me...most likely because of the nested feature, I don't know. I tried editing it, but cant get the results I want. Here's an example of what I would need to edit. I don't think I'll ever come across a need for nested in this particular need.

MsgBox(0,0,StringRegExpReplace("6.~Keep <b>right</b> to continue on <b>white plains blah blah Rd</b><div style='font-size:0.9em'>Destination will be on the right</div>~94((48.8388154, -78.8598753))", "<.*[^<]>", ""))
Edited by Champak

Share this post


Link to post
Share on other sites

Try this...

local $string = "6.~Keep <b>right</b> to continue on <b>white plains blah blah Rd</b><div style='font-size:0.9em'>Destination will be on the right</div>~94((48.8388154, -78.8598753))"
MsgBox(0,0,StringRegExpReplace($string,"<.*?[^<]>", " "))

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Thanks, that's perfect. I would never have thought of the question mark.

Share this post


Link to post
Share on other sites

Glad it worked.   I just altered the patterns from above from greedy to non-greedy and added a space for readability.


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Um... try running that on my string kylomas, that's the exact expression I had that I changed.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

@SmOken_N - Yes, I alluded to your answer in my response.  The OP says that there will be no nested groups...


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

k, well "<.*?>" would work the same then.

Edit:

This might be better so there aren't leading and trailing spaces even.

StringRegExpReplace($sString, "(?s)\h*<.*?>\h*", " ")
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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  
Followers 0