Need advice on regex for searching text in files

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
nemadeka
Junior Member
Junior Member
Posts: 82
Joined: 2009-04-26, 19:44 UTC

Need advice on regex for searching text in files

Post by *nemadeka »

G'day,
I have 99 Word documents which I will translate.
Some of them have numeric values joined with the units, like 60Hz instead of 60 Hz.
This will cause problems in quality check after translation, so I need to separate the units in MS Word.
I don't want to open all the Word documents, but only those with the issues.
So I need a regular expression in the "Find text:" field of the file search window (Alt+F7) for (any digit)(not a space)(units) which would allow me to find only the files where I must make changes.
In MS Word it would be [0-9][!^32]@Hz
Unfortunately, TC Help seems too complex for me, I failed to create a search string, I would greatly appreciate your help.
Thank you! :^)
User avatar
Stefan2
Power Member
Power Member
Posts: 4153
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Need advice on regex for searching text in files

Post by *Stefan2 »

TC Regular expressions Help:
\d a digit
\s a word separator (space, tab etc)
\S no word separator
+ one or more occurrences


So one could think: \d+\SHz would match
one-or-more digits [0-9], followed by "not an space", followed by literal "Hz"
But in real it try to match:
one-or-more digits [0-9], followed by one sign which is "not an space", followed by literal "Hz"
So it would match something like: 60xHz , not 60Hz

To match 60Hz try: \d+Hz
to match one-or-more digits [0-9], directly followed an by literal "Hz"
Or explicit \d\dHz
to match two digits [0-9], directly followed an by literal "Hz"




That?
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Re: Need advice on regex for searching text in files

Post by *gdpr deleted 6 »

Ignore this. I was dumb...
Last edited by gdpr deleted 6 on 2021-02-03, 10:59 UTC, edited 1 time in total.
nemadeka
Junior Member
Junior Member
Posts: 82
Joined: 2009-04-26, 19:44 UTC

Re: Need advice on regex for searching text in files

Post by *nemadeka »

Thanks for the tutorial, Stefan, I have been able to filter the documents according to my criteria.
nemadeka
Junior Member
Junior Member
Posts: 82
Joined: 2009-04-26, 19:44 UTC

Re: Need advice on regex for searching text in files

Post by *nemadeka »

Thanks for your clarifications, elgonzo, I simply use "\dHz" or "pos.\d" it works.
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Re: Need advice on regex for searching text in files

Post by *gdpr deleted 6 »

I guess i made mistake when suggesting my version of the regex. I failed to account for possible SI prefixes preceding the "Hz". So, stefan2' regex comes closer to what you want, although the \S used to match SI prefix should be an optional occurence, i.e.:

\d+\S?Hz

(The ? defines that the preceding symbol - the \S - will match either only once or match nothing)
nemadeka
Junior Member
Junior Member
Posts: 82
Joined: 2009-04-26, 19:44 UTC

Re: Need advice on regex for searching text in files

Post by *nemadeka »

Which pretty much illustrates the "modest" quality of TC help. It should certainly be improved, because features should be easily available to all users, not only the so-called gurus.
For your information, I wrote a macro which does find/replace in Word, it is for preparing data for translation.
The find/replace passes extensively use regex.
You can check its manual here -- https://enru.nemadeka.com/tagger.htm
It is very long, because I needed to make it very clear to anyone.
gdpr deleted 6
Power Member
Power Member
Posts: 872
Joined: 2013-09-04, 14:07 UTC

Re: Need advice on regex for searching text in files

Post by *gdpr deleted 6 »

nemadeka wrote: 2021-02-03, 11:41 UTC Which pretty much illustrates the "modest" quality of TC help. It should certainly be improved, because features should be easily available to all users, not only the so-called gurus.
Well, i am not sure if you are referring to my last comment. But if you do, and valid arguments for TC's help needing improvement not withstanding (we are in agreement about this, i guess), i don't understand how TC's help would be to blame for my inability to read your first post correctly... :D
User avatar
petermad
Power Member
Power Member
Posts: 14791
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Need advice on regex for searching text in files

Post by *petermad »

Well, in the bottom of TC's help for regExp it says:
Total Commander uses the free Delphi library TRegExpr by Andrey V. Sorokin, which is now available at https://regex.sorokin.engineer
So there is all the more comprehensive help you ned, I guess...?
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
nemadeka
Junior Member
Junior Member
Posts: 82
Joined: 2009-04-26, 19:44 UTC

Re: Need advice on regex for searching text in files

Post by *nemadeka »

Thanks again guys, I really appreciate your help.
Post Reply