#1 2017-01-10 21:53

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 29

RegEx rearrange help...

Hi Folks.
Given a set of names like:
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038%2Fscientificamericanmind1116-10b] Knight, Meredith -- Weight-Loss Surgery Alters the Brain.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038%2Fscientificamericanmind1116-25] Steinberg, Louisa J. -- Sleep No More.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038%2Fscientificamericanmind1116-38] Cooperrider, Kensy; Núñez, Rafael -- How We Make Sense of Time.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038%2Fscientificamericanmind1116-58] Bangasser, Debra A. -- Stress.pdf

I'd like them changed to:
MIND -- Weight-Loss Surgery Alters the Brain (Knight, Meredith, 2016).pdf
MIND -- Sleep No More (Steinberg, Louisa J., 2016).pdf
and so on...

I'm using RegexBuddy with PRCE definitions, and it does indicate that this regex

(Scientific American Mind Volume [0-9]* issue [0-9]* )(2016)( \[\N*\] )(\N*)( -- )(\N*)

Does match the 4 samples above. 

I don't think ReNamer recognizes it as proper syntax though...

I'm only a beginner with regex, and I'm not a programmer.  But my thought is to capture these groups
1(Scientific American Mind Volume [0-9]* issue [0-9]* )
2(2016)
3( \[\N*\] )
4(\N*)
5( -- )
6(\N*)

And rearrange (some of) them like this:

MIND -- $6 \($3, $2\)

(I just realized that I have the literal "2016" in there, but I'll fix that later.) 

Thoughts?

Offline

#2 2017-01-10 22:08

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 832

Re: RegEx rearrange help...

FROM:
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038-10b] Knight, Meredith -- Weight-Loss Surgery Alters the Brain.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038-25] Steinberg, Louisa J. -- Sleep No More.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038-38] Cooperrider, Kensy; Núñez, Rafael -- How We Make Sense of Time.pdf
Scientific American Mind Volume 27 issue 6 2016 [doi 10.1038%2-58] Bangasser, Debra A. -- Stress.pdf

TO:
MIND -- Weight-Loss Surgery Alters the Brain (Knight, Meredith, 2016).pdf
MIND -- Sleep No More (Steinberg, Louisa J., 2016).pdf
MIND -- How We Make Sense of Time (Cooperrider, Kensy; Núñez, Rafael, 2016).pdf
MIND -- Stress (Bangasser, Debra A., 2016).pdf

RULE:
Match the year of the 'issue 6 2016' part as $1
Match everything between ']' and '--' as $2
Match all from '-- ' till the end as $3

USE:
RegEx rule
Expression: ^.+issue \d+ (\d\d\d\d) .+] (.+) (--.+)$
Replace: MIND $3 ($2, $1)
[x]Skip extension



HTH?

Explanation:

^.+issue \d+ (\d\d\d\d) .+] (.+) (--.+)$

^            >> anchor start of string
.+           >> match one-or-more of everything, till
issue \d+    >> match 'issue' followed by one-or-more digits, till
(\d\d\d\d)   >> match four digits as year, store as $1
" .+] "      >> match space, one-or-more of everything, closing bracket (reg ex meta sign, but single closing one, so fine) 
(.+)         >> match one-or-more of everything between ']' and ' --', store as $2
(--.+)$      >> match '--' and the rest till the end, store as $3.




 

Last edited by Stefan (2017-01-10 22:19)


For more help and how-to's  read our fine Wiki.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#3 2017-01-10 23:33

kunkel321
Member
From: Washington State
Registered: 2012-09-01
Posts: 29

Re: RegEx rearrange help...

Far out ...  That's quite different from mine.  Many Thanks Stefan!  big_smile

As it turns out, my name is also Stefan.  Well...  "Stephen" actually. smile

Additional question:  Is this a "Pascal flavor" of RegEx?  I also see that a Delphi tool is mentioned at the bottom of the help docs...

Offline

#4 2017-01-12 16:10

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 832

Re: RegEx rearrange help...

kunkel321 wrote:

Additional question:  Is this a "Pascal flavor" of RegEx?
I also see that a Delphi tool is mentioned at the bottom of the help docs...

The free TRegExpr library is used here. (Same as with TotalCmd)
Which, in turn, use a "normal / default" Perl -like syntax.


More information:

http://www.den4b.com/wiki/ReNamer:Regular_Expressions

http://regexpstudio.com/TRegExpr/TRegExpr.html
http://regexpstudio.com/TRegExpr/Help/r … yntax.html




 


For more help and how-to's  read our fine Wiki.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

Board footer

Powered by FluxBB