You are here: PSPad forum > English discussion forum > Need help on Replacement Expression

Need help on Replacement Expression

Goto Page: 1 2 3 Next

#1 Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 09:48 | IP: IP Logged

Need help on Replacement Expression
I need help for "Back Reference" results

URL Match:
\.ru/(20[01][0-9]|2020)/0*([1-9]|1[0-2])/(\d+[-/]\d+)

Sub-Folder Name:
Replace with:???

number_number_number_number
AND
number_number_number-number

image

Edited 3 time(s). Last edit at 2020-03-31 09:53 by maki.

Options: Reply | Quote | Up ^


#2 Re: Need help on Replacement Expression

Posted by: pspad | Date: 2020-03-31 10:08 | IP: IP Logged

Each group is enclosed into ()

(group1)(group2)(group3)

in the result you can use reference to groups using $1...$n

e.g. I have number 123 and I want in the result 231
search: (\d)(\d)(\d)
replace: $2$3$1

Options: Reply | Quote | Up ^


#3 Re: Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 11:05 | IP: IP Logged

Example How to use pattern
My regex:
\.ru/([^/]+)/([^&\?/]+)

Replace:
[#1]_[#2]

result:
1234_1234

Correct!

Test:
\.ru/((20[01][0-9]|2020))/(0*([1-9]|1[0-2]))/((\d+[-/]\d+))
[#2]_[#3]_[#5]

Result:
2018_01
2018_01_20/1976

Invalid result

Edited 2 time(s). Last edit at 2020-03-31 11:08 by maki.

Options: Reply | Quote | Up ^


#4 Re: Need help on Replacement Expression

Posted by: pspad | Date: 2020-03-31 11:08 | IP: IP Logged

maki:
Test:
[#2]_[#3]_[#5]

Result:
2018_01
2018_01_20/1976

Invalid result

When you will write your request to be understable, you will get answer.
Sorry, but this one isn't

Real search line example, real result you want is good start.

Options: Reply | Quote | Up ^


#5 Re: Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 11:28 | IP: IP Logged

\0
Indicates a back reference to the entire regular expression.

\1 - \9
Indicates a back reference a back reference is a reference to a previous sub-expression

$10, $11, $12, ...
Indicates a back reference more than 9

I use all combinations, and this is incorrect:
But it returns the wrong result.

Options: Reply | Quote | Up ^


#6 Re: Need help on Replacement Expression

Posted by: pspad | Date: 2020-03-31 11:43 | IP: IP Logged

Read my first answer and use it. It works.

Options: Reply | Quote | Up ^


#7 Re: Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 11:55 | IP: IP Logged

Url contains:
\.ru/(.*?)/(.*?)(?:$|\?|#).*

...then set:
Filename: \1_\2
Use:
\ or $

This is valid conditions match, but not for all applications sad smiley

ht_p://website:/2020/10/234/3454
ht_p://website:/2020/10/234-3454

Filename Result:
2020_10_234_3454
AND
2020_10_234-3454

Edited 1 time(s). Last edit at 2020-03-31 11:56 by maki.

Options: Reply | Quote | Up ^


#8 Re: Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 14:29 | IP: IP Logged

Your pattern is extremely simple. I understand that.
But my pattern is not of the type "Expert":
I have 3 choices:
"Basic"
"Advanced"
and "Expert"

Ask for "Expert" smiling smiley

Edited 2 time(s). Last edit at 2020-03-31 14:30 by maki.

Options: Reply | Quote | Up ^


#9 Re: Need help on Replacement Expression

Posted by: pspad | Date: 2020-03-31 14:54 | IP: IP Logged

In your expression create groups using () and use substitution.
What don't you understand?

Options: Reply | Quote | Up ^


#10 Re: Need help on Replacement Expression

Posted by: maki | Date: 2020-03-31 15:00 | IP: IP Logged

My target file are named: URL for file name
so your examples don't match any url!

"/"
is an illegal character in the name so replace "_"

I am asking for a template for the addresses I gave at the beginning of the post.

Edited 2 time(s). Last edit at 2020-03-31 15:03 by maki.

Options: Reply | Quote | Up ^


Goto Page: 1 2 3 Next





Editor PSPad - freeware editor, © 2001 - 2021 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR