Jump to content

StringRegExpReplace assistance


Go to solution Solved by Nessie,

Recommended Posts

  • Moderators

I am hoping someone who does a lot more with StringRegExp can assist with this, as it makes my eyes bleed. I am trying to strip the OU, CN, DC and = (but leave the commas) from an FQDN for a container in A.D. An example of the pattern is below, thus far I've tried a couple of things but am not getting the expected result.

Pattern : OU=Non-Citrix Production ,OU=XenApp and Citrix Servers,OU=Citrix,DC=my,DC=domain

Desired Outcome : Non-Citrix Production ,XenApp and Citrix Servers,Citrix,my,domain

The closest I have come is with something like this:

StringRegExpReplace($string, "(?-i)[DC=CN=OU=]", "", 10)

That returns the following: on-itrix Production,XenApp and itrix Servers,U=Citrix,DC=my,DC=domain

Any suggestions are appreciated.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Solution

Maybe this?

$string = "OU=Non-Citrix Production\ ,OU=XenApp and Citrix Servers,OU=Citrix,DC=my,DC=domain"
$regex = StringRegExpReplace($string, "[OU|CN|DC]+=", "", 0)
Display($string, $regex)

Func Display($sInput, $sOutput)
; Format the output.
Local $sMsg = StringFormat("Input:\t%s\n\nOutput:\t%s", $sInput, $sOutput)
MsgBox(0, "Results", $sMsg)
EndFunc ;==>Display

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

$string = "OU=Non-Citrix Production\ ,OU=XenApp and Citrix Servers,OU=Citrix,DC=my,DC=domain"

MsgBox(64, "Result", "Input: "& $string & @CR & "Output: " & StringRegExpReplace($string, "(OU|CN|DC)=", ""))

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • Moderators

Thanks, all, for the suggestions. Unfortunately, SRE is something I've always shied away from, just makes my head hurt :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

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...