A bit of regex help needed

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

First case:

Code: Select all

Intr > 
There is a space after the >!

Second case:

Code: Select all

Intr > Ex
But I don't see the need to use a regex here, search & replace would be able to do the same. But nevertheless, no special syntax necessary :)
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1620
Joined: 13 Jan 2011 19:44

Re: A bit of regex help needed

Post by eil »

em.. none of those work for selecting multiple files and pushing F2 :(
Attachments
06-20_144145.png
06-20_144145.png (10.33 KiB) Viewed 3254 times
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

You asked for a regex pattern. Ofc you have to use regexp rename... :)
One of my scripts helped you out? Please donate via Paypal

eil
Posts: 1620
Joined: 13 Jan 2011 19:44

Re: A bit of regex help needed

Post by eil »

oh, now i see. for some reason i thought this form already includes batch + regex depending what you state in input. seems like i'll have to reassign my shortcuts for rename.) or maybe there is a way to state what kind of F2-rename i want when many files are selected?(as i see F2 is for simple rename but when many files selected Batch comes in place, thogh it's assigned to Shift+F2
Last edited by eil on 20 Jun 2015 15:12, edited 1 time in total.
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

You mean batch rename? No.

You have to use either regexp rename... or search & replace...

My pattern was for the regexp variant but your "problem" can easily solved by search & replace... as well.
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

look for\search text
\s

replace with\replacement text
a/\n

This works fine but with each document's last line. Which 'look for' I could use so the entire document is done on a single pass?

edit: it turns out the replacement generates <lf> separated lines, not <crlf>. How could I fix this too?
Last edited by tiago on 21 May 2016 22:09, edited 1 time in total.
Power-hungry user!!!

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

I don't understand...

Show a screenshot of what is happening and what should have happened...
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

Sure.
Please consider the edit I did.
a\r\n solves the <crlf> problem I guess.
expected Result.png
expected Result.png (6.5 KiB) Viewed 3154 times
Attachments
regex Problem.png
regex Problem.png (29.76 KiB) Viewed 3154 times
Power-hungry user!!!

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

You want to replace all line ending u's with a's in the whole document?

Search for: u$
Replace with: a
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

Yes.
Being the problem the last line of each document.
Power-hungry user!!!

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

$ matches each line ending, even the one of the last line so what I suggested should work
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

Worked. Thank you!
Power-hungry user!!!

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

Input:
? h4\static\Windows\win32\Manifests\x86_microsoft-windows-ndisuio.resources_31bf3856ad364e35_6.1.7600.16385_pt-br_9dc57ae50d7ad254.manifest
d4\optim\Windows\winsxs\x86_ph3xibc9.inf_31bf3856ad364e35_6.1.7600.16385_none_4482afc18dfa7358
! r3\static\Windows\win64\x86_netgb6.inf_31bf3856ad364e35_6.1.7600.16385_none_33c0abd150a8143e

Output:
? h4\static\Windows\win32\
d4\optim\Windows\winsxs\
! r3\static\Windows\win64\

How can I get this using regexreplace sc, please?
Power-hungry user!!!

highend
Posts: 13311
Joined: 06 Feb 2011 00:33

Re: A bit of regex help needed

Post by highend »

Nothing easier than that:

Code: Select all

    $a = <<<>>>
? h4\static\Windows\win32\Manifests\x86_microsoft-windows-ndisuio.resources_31bf3856ad364e35_6.1.7600.16385_pt-br_9dc57ae50d7ad254.manifest
d4\optim\Windows\winsxs\x86_ph3xibc9.inf_31bf3856ad364e35_6.1.7600.16385_none_4482afc18dfa7358
! r3\static\Windows\win64\x86_netgb6.inf_31bf3856ad364e35_6.1.7600.16385_none_33c0abd150a8143e
>>>;

    text regexreplace($a, "^((?:.*?\\){4})(.*?$)", "$1");
One of my scripts helped you out? Please donate via Paypal

tiago
Posts: 589
Joined: 14 Feb 2011 21:41

Re: A bit of regex help needed

Post by tiago »

Hello, highend! Thanks for the prompt reply on this busy saturday I'm having.
As far as I can tell your code splits elements to the first 4 tokens '\' divided, right?
Say I'd need to state manually

? h4\static\Windows\win32\Manifests\
or
d4\optim\Windows - yes, no '\' here.
or
! r3\static\

what could I do?
Power-hungry user!!!

Post Reply