John117

String strip or replace

11 posts in this topic

Hey, I'm not that great with String Replace or String Strip where the exact string is not known.

 

I need to be able to strip the following:

"2015">2015

Where 2015 may not be known. I need to basically strip the side "*>  where * behaves like a wild card and leaves only the right side 2015.

Length will not be known. It will not always be numerical.

It may be " * > or < * > but I can set these for each column according to which way it is set up. 

Please help. Just need a basic understanding of how to identify and replace the pattern with ""

 

Share this post


Link to post
Share on other sites



Can you provide some other examples of possible strings ?

If I understand, you want to keep only the last digits, am I right ?

$string = '"2015">2015'
$newstring = StringRegExpReplace($string, ".+?(\d+)$", "$1")
ConsoleWrite($newstring)

 

Share this post


Link to post
Share on other sites

...or remove all up to the last  ">" (included) ?

$string = '"2014">2015'
$newstring = StringRegExpReplace($string, ".*>", "")
ConsoleWrite($newstring)

 

Share this post


Link to post
Share on other sites

Thanks for your reply. Here are a few examples.


                                <span title="111">111

                                <span title="3.5L 6 cyl Fuel Injection">3.5L 6 cyl Fuel Injection

                                <span title="Ultra White">Ultra White

                                <span title="Black/garnet">Black/garnet

Share this post


Link to post
Share on other sites

This is what I have so far. Yours works great for the numerical portions.

StringReplace(StringRegExpReplace($Array2[0], "\>.*", ""), '"', "")

Share this post


Link to post
Share on other sites

Ok so using your code I've been able to clear everything except 

"
                 title="$44,900"

 

StringReplace(StringRegExpReplace($Array2[0], ".*>", ""), '"', "")

Share this post


Link to post
Share on other sites
StringRegExpReplace($Array2[0], '<\V+title="([^"]+)".+', "$1")

 

$string = 'title="$44,900"'
$String2 = StringRegExpReplace($string, '<\V+title="([^"]+)".+', "$1")
Consolewrite($String2 & @CRLF)

 

Doesn't look like that one works. 

Share this post


Link to post
Share on other sites

Thanks for the reply. That one's not set up like that. In that case $Array2[0]    is    title="$44,900"

Share this post


Link to post
Share on other sites

This is what I am using on that single one for now. StringStripWS(StringReplace(StringReplace($Array2[0], 'title="$', ''), '"', ''), $STR_STRIPALL)

 

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