Jump to content

Recommended Posts

Posted

i have text file like this:

2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet

2011-1-10 9:24:18> is a tata & time.

i want remove this (2011-1-10 9:24:18> ) string from line.

thanks

Posted

Trimleft may have issues because the hour column changes from one to two digits

$string = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet"

$new = stringregexp ($string , "http://(.*)" , 1)

msgbox (0, '' , 'http://' & $new[0])

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

  • Moderators
Posted

shai,

StringTrimLeft will not work if the data/time has a varying number of characters: :P

2011-1-10 9:24:18> = 19 Chars

2011-11-30 15:24:18> = 21 chars

I believe you are correct to want to use a RegEx - this should work in all cases: :shifty:

$sText_1 = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet"
$sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1")
ConsoleWrite($sURL_1 & @CRLF)

$sText_2 = "2011-11-30 15:24:18> http://www.google.com/search?hl=en&safe=on&q=internet"
$sURL_2 = StringRegExpReplace($sText_2, "(?i).*?> (.*)", "$1")
ConsoleWrite($sURL_2 & @CRLF)

Just to explain the SRE a bit:

(?i) = case insensitive

.*?> = A non-capturing group of the shortest run of characters ending in "> "

(.*) = A capturing group of the rest of the line

$1 = Replace with the first (and in this case only) capturing group

I hope all that makes sense - my brain starts to bleed when I deal with SREs. :x

M23

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

 

Posted

shai,

StringTrimLeft will not work if the data/time has a varying number of characters: :P

2011-1-10 9:24:18> = 19 Chars

2011-11-30 15:24:18> = 21 chars

I believe you are correct to want to use a RegEx - this should work in all cases: :shifty:

$sText_1 = "2011-1-10 9:24:18> http://www.google.com/search?hl=en&safe=on&q=internet"
$sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1")
ConsoleWrite($sURL_1 & @CRLF)

$sText_2 = "2011-11-30 15:24:18> http://www.google.com/search?hl=en&safe=on&q=internet"
$sURL_2 = StringRegExpReplace($sText_2, "(?i).*?> (.*)", "$1")
ConsoleWrite($sURL_2 & @CRLF)

Just to explain the SRE a bit:

(?i) = case insensitive

.*?> = A non-capturing group of the shortest run of characters ending in "> "

(.*) = A capturing group of the rest of the line

$1 = Replace with the first (and in this case only) capturing group

I hope all that makes sense - my brain starts to bleed when I deal with SREs. :x

M23

ok its work perfect.

now if i have a file in desktop the name is "list_address.txt" and in this file i have multiline like this.

i want replace all lines and save the file after replaceing.

  • Moderators
Posted

shai,

Load the file into an array with _FileListToArray - loop through each line and apply the SRE - write the file back to disk with _FileWriteFromArray. Simple! :x

But be careful: the [0] index of the array is the count, so you will need to use the $i_Base parameter when you write the file. :P

M23

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

 

Posted

$sURL_1 = StringRegExpReplace($sText_1, "(?i).*?> (.*)", "$1")

You can simplify the regex:

$sURL_1 = StringRegExpReplace($sText_1, "[^>]*> ", "")

[^>]*> = A non-capturing group of the longest run of characters other than ">" ending in "> "

You don't need to worry about case since it will slurp up everything other than a ">" character.

Gerard J. Pinzonegpinzone AT yahoo.com
Posted

M23,

I'm with ya on that "brain bleedin" thing...

Do these examples assume that there are no ">"'s in the target text?

kylomas

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

  • Moderators
Posted (edited)

GPinzone,

Thanks for that. Always happy to learn about SREs - I make no pretence of being expert at them! :P

M23

Edit: Actually, always happy to learn about anything! :x

Edited by Melba23

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

 

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
×
×
  • Create New...