How do i replace only digits attached with letters
-
i have
PTH 284 Wo, mm4b chunu Awurade
and i want to change only the 4 within the string without affect the 284
so i want to change 4 to e
so the result i need is
PTH 284 Wo, mmeb chunu Awurade -
given your requirement one possible solution would be to
search for\d(?=[a-zA-Z])
, replace withe
and
having search moderegular expression
checked.If the requirement is that the digit is surrounded by letters, then
search for(?<=[a-zA-Z])\d(?=[a-zA-Z])
-
ello @ebenezer-amoako-yirenkyi and All,
To change any number, embedded in letters of a word, use the following regex S/R :
- Open the Replace dialog (
Ctrl + F
)
-SEARCH
(\p{alpha})\d+(?=\p{alpha})
-
REPLACE
${1}
Your replacement ( So${1}e
, in your case ) -
Tick the
Wrap around
option, if necessary -
Select the
Regular expression
search mode -
Click once the
Replace All
button or several times on theReplace
button
Best Regards
guy038
- Open the Replace dialog (
-
@guy038 said in How do i replace only digits attached with letters:
Open the Replace dialog ( Ctrl + F )
Of course you meant Ctrl + h for this.
Nice use of
\p{alpha}
from the Character Properties table on this PAGE which has a link that lead to HERE and then finally HERE to find “alpha”.Perhaps
\p{space}
will start getting more use as a more “readable” way of searching for whitespace? Although I’d have to go off and figure out exactly what types of whitespace it matches. :-)I also noted your use of
${1}
in the replacement, rather than the usual\1
. I think that is a good thing, because it looks “cleaner”, it features no “leaning toothpick”, and it works when the number part is > 9. -
@Alan-Kilborn said in How do i replace only digits attached with letters:
Nice use of \p{alpha} from the Character Properties table on this PAGE which has a link that lead to HERE and then finally HERE to find “alpha”.
Or you could go to our documentation on character properties which direct you to the big old table of valid names right above. :-)
-
@PeterJones said in How do i replace only digits attached with letters:
Or you could go to our documentation on character properties
Yea, since “our” docs on this are pretty much a verbatim copy of the original, I like to go back to the original, because of the “typo” potential in the copy/edit. :-)
-
@Alan-Kilborn said in How do i replace only digits attached with letters:
Although I’d have to go off and figure out exactly what types of whitespace it matches. :-)
Actually, @guy038 did that work back in November:
[\t\n\x0B\f\r\x20\x85\xA0\x{2028}\x{2029}]
(merged in PR#59) …edit: and you would have seen that if you used “ours” instead of “theirs” ;-)
-
Hi @ebenezer-amoako-yirenkyi @alan-kilborn, @peterjones and All,
Alan, I used the
${1}
syntax because I was afraid that, in case you would have preferred to change the4
digit, by any number, this would not work.Luckily, I realize that I was wrong because, for instance, the syntax
\123
, in replacement, always means change current match with contents of group1
, ( even if not defined => an empty string), followed with the number23
So, the two replacement syntaxes
\1
Your replacement or${1}
Your replacement are safe ! Unlike the third syntax$1
Your replacement which is best to avoid when your replacement is a number !BR
guy038
-
@guy038 it worked perfectly
-
@Ekopalypse it worked perfectly thanks for the help