#1 2020-05-27 15:11

maryrabbit
Member
Registered: 2020-05-27
Posts: 2

Regex match before / after year? e.g. 1994 > (1994)

Example, adding parenthesis to before and after the matching year pattern / `\d{4}`:

Name:
Batman 1994
Superman (2003)

New Name:
Batman (1994)
Superman (2003)

I tried positive lookahead/behind but reNamer throws unrecognized modifier error

Offline

#2 2020-05-27 16:15

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

Re: Regex match before / after year? e.g. 1994 > (1994)

Hello and welcome.

The most simplest way is to add parenthesis to all years, if have parenthesis already or not,

and add next an Replace Rule (https://www.den4b.com/wiki/ReNamer:Rules:Replace)

to change doubled parenthesis by single one:

Find: ((*|*))
Replace: (*|*)


- - -

The regex syntax can be read there
https://www.den4b.com/wiki/ReNamer:Regular_Expressions

Right now no lookaround implemented.

- - -

You could use a "must no match" expression [^...]

FROM:
Batman 1994
Superman (2003)

TO:
Batman (1994)
Superman (2003)

USE:
Regular Expressions:
Expression: "[^(](\d{4})[^)]"
Replace: " ($1)"
[x] skip extension




 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2020-05-27 16:18

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Regex match before / after year? e.g. 1994 > (1994)

The following two rules should do the job:

1) Regular Expressions: Replace expression "\b(\d{4})\b" with "($1)"
2) Replace: Replace all "((" with "(", "))" with ")"

Offline

#4 2020-05-27 18:04

eR@SeR
Senior Member
From: Земун, Србија
Registered: 2008-01-23
Posts: 354

Re: Regex match before / after year? e.g. 1994 > (1994)

Or you can use one rule:

1) Regular Expressions: Replace expression "\(?(\d{4})\)?" with "($1)" (skip extension)


TRUTH, FREEDOM, JUSTICE and FATHERLAND are the highest morale values which human is born, lives and dies for!

Offline

#5 2020-05-29 11:56

maryrabbit
Member
Registered: 2020-05-27
Posts: 2

Re: Regex match before / after year? e.g. 1994 > (1994)

It works! thank you @stefan @den4b @eR@SeR !!!

Offline

Board footer

Powered by FluxBB