1

I am trying to make a Ultraedit regex which allows me to remove all words of a txt file containing a number.

For example:

test
test2
t2est
te2st

and...

get only test

user699998
  • 27
  • 7
  • Hi welcome to stack overflow, what have you tried? – Mikhail Jul 21 '15 at 15:56
  • \W(?:[-A-Za-z]+[0-9]) but is not correct – user699998 Jul 21 '15 at 16:54
  • The expression seems ok (at least it matches 3 of these 4 lines), but when I tested this against UES, it behaved rather strange (reported 3 matches but did not show any...), so I'm going to report this to IDMComp. It could be that UE also suffers from that bug. Which version exactly are you using? – MBaas Jul 21 '15 at 18:05
  • version 21.30.0.1016 – user699998 Jul 21 '15 at 19:42
  • I don't see any problem with `\W(?:[-A-Za-z]+[0-9])` in UEStudio v15.20.0.8 and UltraEdit v22.10.0.12. It finds exactly the strings which should be found with this expression. It is not good to use `\W` as this means there must be a non word character before first word character or hyphen. So it would never match for example `test2` being at top of file as there is no non word character. Better solutions are posted below. The hyphen can be added to the classes. But within square brackets it is always better to add a hyphen with a backslash, i.e. `[\-A-Za-z]` instead of `[-A-Za-z]`. – Mofi Jul 23 '15 at 10:00

1 Answers1

1

A case-insensitive search with Perl regular expression search string \<[a-z]+\d\w*\> finds entire words containing at least 1 digit.

\< ... beginning of a word. \b for any word boundary could be also used.

[a-z]+ ... any letter 1 or more times. You can put additional characters into the square brackets like ÄÖÜäöüß also used in language of text file.

\d ... any digit, i.e. 0-9.

\w* ... any word character 0 or more times. Any word character means all word characters according to Unicode table which includes language dependent word characters, all digits and the underscore.

\> ... end of a word. \b for any word boundary could be also used.

A case-insensitive search with UltraEdit regular expression search string [a-z]+[0-9][a-z0-9_]++ finds also entire words containing at least 1 digit if additionally the find option Match whole word is also checked.

[a-z]+ ... any letter 1 or more times. You can put additional characters into the square brackets used in language of text file.

[0-9] ... any digit.

[a-z0-9_]++ ... any letter, digit or underscore 0 or more times.

The UltraEdit regexp search string [a-z]+[0-9][a-z0-9_]++ in Unix/Perl syntax would be [a-z]+[0-9][a-z0-9_]* which could be also used with find option Match whole word checked instead of the Perl regexp search.

Mofi
  • 46,139
  • 17
  • 80
  • 143