Sign in to follow this  
Followers 0
agubler

Replace using regular expression

7 posts in this topic

I am sure this is really simple, but it is melting my mind.

I have a string: "MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public"

The part "Custom["C"]" could have any letter within the quotes i.e. Custom["O"] or Custom["P"]

I need to check the original string "MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public" and if "Custom[""]" exists with any character between the speecharks replace that character with D.

examples

Original string : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public

Required result : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["D"]):Public

Original string : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["O"]):Public

Required result : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["D"]):Public

Original string : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public

Required result : MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public

Is this possible?

Share this post


Link to post
Share on other sites



I'd look up stringinstr

and stringtrimleft and stringtrimright


Giggity

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

How about this?

Dim $String[3]
$String[0] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public'
$String[1] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["O"]):Public'
$String[2] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public'

For $x = 0 to 2
$NewString = StringRegExpReplace($String[$x], '\[\"\w\"\]', '["D"]')
Msgbox(0,"","Original String: "&$String[$x]&@CRLF&"Resut: "&$NewString)
Next
Edited by Paulie

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

$DATA = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public'
MsgBox(0,"",StringReplace($DATA,'Custom["C"]','Custom["D"]'))

EDIT: This work only if custom is C.

Edited by Andreik

When the words fail... music speaks

Share this post


Link to post
Share on other sites

$DATA = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public'
MsgBox(0,"",StringReplace($DATA,'Custom["C"]','Custom["D"]'))
I think he wanted to use regex because the 'Custom["C"]' could be any character A-Z

..at least that's what I gathered...

Share this post


Link to post
Share on other sites

I think he wanted to use regex because the 'Custom["C"]' could be any character A-Z

..at least that's what I gathered...

Yes you have right. I was not careful. Thank you corrected me.

When the words fail... music speaks

Share this post


Link to post
Share on other sites

How about this?

Dim $String[3]
$String[0] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["C"]):Public'
$String[1] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public(Custom["O"]):Public'
$String[2] = 'MarketDeadlineDate (Title "O - Market Deadline DateTime"):Public'

For $x = 0 to 2
$NewString = StringRegExpReplace($String[$x], '\[\"\w\"\]', '["D"]')
Msgbox(0,"","Original String: "&$String[$x]&@CRLF&"Resut: "&$NewString)
Next
Paulie

that is perfect, exactly what i was looking for. yeah the "C" could be any character. thanks alot

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