Jump to content

Using StringRegexp to replace patterned strings


Randolph
 Share

Recommended Posts

Good Day,

Appreciate some help on this; i've got the below text and i'm trying to replace the "[xx;xxH" patterns before each string. xx is a number that can either be 2 digits or single-digit. I've got the below, but it doesn't appear to work; appreciate any help please; thanks.

Code

$rel = StringRegExp("[15;1HAdam Biggs", "[(\d{2});(\d{2})H", 'aaaaa')

_ArrayDisplay($rel)

Sample text to clean:

[14;1HAbigail Mulliga[14;17H10366693 [14;31H103-40521[14;45HOther [14;53H12:36[14;60H 0[14;68H 0[14;76H 0[15;1HAdam Biggs [15;17H10366748 [15;31H103-40407[15;45HOther [15;53H12:36[15;60H 0[15;68H 0[15;76H 1[16;1HAdam Rogers [16;17H10366694 [16;31H103-40519[16;45HAUX [16;53H12:38[16;60H 0[16;68H 0[16;76H 0[17;1HAde Mafo [17;17H10366695

Link to comment
Share on other sites

  • Moderators

Randolph,

Try this one: :D

$sText = "[14;1HAbigail Mulliga[14;17H10366693 [14;31H103-40521[14;45HOther [14;53H12:36[14;60H 0[14;68H 0[14;76H 0[15;1HAdam Biggs [15;17H10366748 [15;31H103-40407[15;45HOther [15;53H12:36[15;60H 0[15;68H 0[15;76H 1[16;1HAdam Rogers [16;17H10366694 [16;31H103-40519[16;45HAUX [16;53H12:38[16;60H 0[16;68H 0[16;76H 0[17;1HAde Mafo [17;17H10366695"

$sNewText = StringRegExpReplace($sText, "\[\d+;\d+H", 'aaaaa')

ConsoleWrite($sNewText & @CRLF)

Any help? ;)

M23

P.S. Do you realise you have some non-printing characters in your posted string? :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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