#1 2021-09-03 21:11

GaryF
Member
Registered: 2021-09-01
Posts: 10

Mired in RegEx: Find "E" plus Digit and put "0" zero in between

At the moment I can't make head nor tail of Regex. Nothing about it makes sense so it's going to be a while before I learn anything at all.
In the meantime: I have a column of text, E1, E2, E3, E4 etc etc. I simply want to add a zero after the E. I know there's some black magic in RegEx that can do it but I have no clue where to find it.
Anyone?

Offline

#2 2021-09-04 12:27

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

Re: Mired in RegEx: Find "E" plus Digit and put "0" zero in between

It is not that hard. Put both "E" and digit(s) in the group and put "0" between both references:

1) Regular Expressions: Replace expression "(E)(\d+)\b" with "$1\0$2" (skip extension)

From:

E1
E2
E3
E40
E500

To:

E01
E02
E03
E040
E0500

If you want to put "0" only for digits from 0 to 9 just remove + sign.


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

Offline

#3 2021-09-04 12:40

GaryF
Member
Registered: 2021-09-01
Posts: 10

Re: Mired in RegEx: Find "E" plus Digit and put "0" zero in between

It's very hard when you don't know what you need to look for. Most tutorials on RegEx assume prior knowledge of coding so there's no baseline teaching.
I work things out from expressions that I see working, and this one does. I very much appreciate your time on this, and I learned something that can cover many different scenarios, thank you.

Offline

#4 2021-09-04 14:06

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

Re: Mired in RegEx: Find "E" plus Digit and put "0" zero in between

There is a small crash course available on the wiki, it doesn't assume any prior knowledge, I think:

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

Offline

#5 2021-09-04 15:02

GaryF
Member
Registered: 2021-09-01
Posts: 10

Re: Mired in RegEx: Find "E" plus Digit and put "0" zero in between

It's not bad but it is dry, cold reference. It has no examples so doesn't relate to real world for me.

The two fixes I've had ne here have been great I've now got 8 presets working based on the two I got here. It took a bit of playing before I properly understood what it was doing but having the before and after helped me.

I have pretty much everything I need now, most operations can be done by replace or remove so the few expressions I have make it almost complete.

Thanks again for the help smile

Last edited by GaryF (2021-09-04 17:35)

Offline

#6 2021-09-04 23:24

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

Re: Mired in RegEx: Find "E" plus Digit and put "0" zero in between

GaryF wrote:

Most tutorials on RegEx assume prior knowledge of coding so there's no baseline teaching.

I recommend you to watch the course Learning regular expressions by Kevin Skoglund. He demystified them completely with real-life examples. It helped me a lot to understand them even better. It might help you too and any other interested in this topic. Once learned, they are real power working with text. You don't have to know any programming language in order to use them smile


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

Offline

Board footer

Powered by FluxBB