#1 : 19/05-21 06:21 yuezhang
Posts: 4
|
I want to leave the last part like "word+000" combination, remove anything before:
Like: “34_ert345wers000” would become "wers000" "fdsf_grge000" would become "grge000" "#^%^$%jnrjr000" would become "jnrjr000" I tried replace method, Text to be replaced: (.+)(\w*000) Replace with: $2 But it didn't work properly, the regular expressions will always search from left to right, so it cannot decide (\w*000) first and then decide the left. |
#2 : 19/05-21 09:13 David Lee
Posts: 1125
|
You have two problems...
1) The metacharacter \w will match numerical digits and underscore as well as letters ie \w = [a-zA-Z0-9_] so you need to explicitly define the characters you wish to match as [a-z] (or [a-zA-Z] if your regex is case-sensitive). 2) The "+" & "*" modifiers are "greedy" by default so ".+" will match everything - including word characters - up to "000" in your regex. The solution is to append "?" to the modifier, which is an instruction for the modifier to be "lazy". So... Replace: .*?([a-z]*000$) With: \1 |
#3 : 19/05-21 11:14 yuezhang
Posts: 4
|
Reply to #2:
That's worked out so well, Thank you very much! Meanwhile I learnt a lot, thank you! |