I have the following line:
01/01/2014 blbalbalbalba blabla / blabla
I would like to replace the last slash with a space and keep the first two slashes in the date.
The closest thing I came up with was this:
PS E:\> [regex] $regex = '[a-z]' PS E:\> $regex.Replace('abcde', 'X', 3) XXXde
but I don’t know how to start from the end of the line. Any help would be greatly appreciated.
Editing my question to clarify: I just want to replace the last slash character with a space, so:
01/01/2014 blbalbalbalba blabla / blabla becomes 01/01/2014 blbalbalbalba blabla blabla
Knowing that the length of "blabla" varies from one line to another, and the slash character can be anywhere.
Thank:)
:
(.*)[/](.*)
$1 $2
(.*) , ( ). , , placeholder $, ( , , $1 ), replace, , , . 01/01/2014 blbalbalbalba blabla
(.*)
$
$1
01/01/2014 blbalbalbalba blabla
[/] .
[/]
(.*) , , . blabla, $2 placeholder.
blabla
$2
, , , , . " " (.. ), , . , , , , [/] .
lookahead:
'01/01/2014 blbalbalbalba blabla/blabla' -replace '/(?=[^/]+$)',' ' 01/01/2014 blbalbalbalba blabla blabla
'/(? = [^/] + $)' '/', 'not/' EOL, , , , .
'01/01/2014 blbalbalbalba blabla/blabla' -replace '^(\d{2}/\d{2})/(\d{4} .*)','$1 $2' # outputs this: # 01/01 2014 blbalbalbalba blabla/blabla
Here you can do it without regular expressions:
$string = "01/01/2014 blbalbalbalba blabla/blabla" $last_index = $string.LastIndexOf('/') $chars = $string.ToCharArray() $chars[$last_index] = ' ' $new_string = $chars -join ''
Another way:
$string = "01/01/2014 blbalbalbalba blabla/blabla" $last_index = $string.LastIndexOf('/') $new_string = $string.Remove($last_index, 1).Insert($last_index, ' ')
$ is the anchor for the end of the line. So (. *?) ([A-d]) $
should match what you want, and the thing in () is what you want to replace.
Regards
Source: https://habr.com/ru/post/1547192/More articles:What is the order of the Component.onCompleted components in a QML file with many elements? - qtQMetaMethod from member function pointer - c ++мульти-select тегированный тип значения в архитектуре предприятия - enterprise-architectHow can I manually register the html-help file in the Delphi (RAD Studio) XE6 online documentation? - delphiIn graphicsmagick, how can I specify the output file for a large number of files? - graphicsmagickHow to fix vulnerable context help in the IDE Delphi 2010 - delphiSpecial Excel taskbar not displaying - excelvim on ultra-high display (3200-1800) on Windows 8 - vimExcel VSTO Addin shows / hides taskbar - c #Opendaylight, Mininet и Ubuntu. Нет ARP, нет ping - ubuntuAll Articles